Get Post ID of the viewed page instead of the Post ID of the cloud template

Posted in: Newspaper
Post count: 17

I’m adding a custom tagDiv composer block which will retrieve postmeta information for the post, then display that information on the page. This means I need to get access to the post ID of the post. But in testing I continuosly get the post ID of the cloud template instead. From within the context of a tagDiv composer block how can I reliably get the original post ID?

The oddest thing is that it appears to depend _where_ in the cloud template I place my block. If I place it in the content area it pulls the post information as expected. However if I place it above the title it tries to get template details. I’ve dumped out the following things in both cases.

var_dump($post->ID);
var_dump($wp_query->post->ID);
var_dump(get_the_ID());
var_dump(get_queried_object_id());

Am I doing something wrong?

Post count: 17

After looking through other modules in your plugin I discovered you have a global to handle this:


$single_post_details = $tdb_state_single->get_wp_query();
Post count: 21065

Hello!

Did you solved your problem?

Thank you!

Post count: 10

A solution would be very useful. All shortcodes using get_the_id() or get_the_post() will fail. In my case the shortcodes work only inside the »external Shortcode« Block, which doesn’t allow line breaks and markup.
Would be great having a good way to handle this.

Thanks!

Post count: 21065

Hi,

Please send an email at contact@tagdiv.com and provide wp-admin and Cpanel access, so we can investigate this issue. Also paste a link to this topic so we can easily identify you.
Let us know and we will gladly assist you.

Thanks!

Post count: 17

@Bettina, I’m sorry but I’m still having this issue. To be more clear.

Post ID 36027 has an associated author of Web Webster (user ID 16).

My tagDiv module attempts to retrieve the field pen_name for this post, and if it doesn’t find one if falls back to using the WordPress function get_the_author() which returns Gaby Gaass (user ID 5) because she is the person who edited the cloud template we’re using.


$pen_name = get_post_meta($post_id, 'pen_name', true);
$pen_name = $pen_name ? $pen_name : get_the_author();

I could use your built-in function $tdb_state_single->get_wp_query(). But since it returns the post_author ID and not the author name, I’d have to perform an additional database query to retrieve that. I would be lovely if that was included.

Post count: 21065

Hello!

If you sent an email, then we will take a look and reply to you as soon as possible.

Thank you for understanding!

Post count: 104

Commenting part to follow this as I have a similar issue I am working on some custom code Woocommernce Membership plugin and I need to retrieve the Post_ID, but it seems the code pulls the post_id from the actual post then it retrieves the post_id from the template overriding the variable.

Post count: 35449

Hi elvisfrog, unfortunately, I do not quite understand, the post_id that you get is not the good one ? can you provide a little some more details, maybe some example too, this will help to understand what you need to achieve.
Thank you!

Viewing 9 posts - 1 through 9 (of 9 total)
The forum ‘Newspaper’ is closed to new topics and replies.