Can't get correct Post ID using cloud template

Posted in: Newspaper
Post count: 4

When i try to get post ID it returns the ID of the cloud template not the ID of the actual single post.

the cloud template ID is:215 the single post ID is:1911 the following code will only output 215

`

function metavalue() {
global $post;
$meta = get_post_meta($post->ID, 'product_url', true);
return $meta
}
add_shortcode('url_short', 'metavalue');

get_the_ID(); the_id(); $post->ID; will also output 215. i need a way to get the actual single post ID so i can get the custom field value from ‘product_url’.

  • This topic was modified 7 years by vexicon.
Post count: 23312

Hi,

Provide your website URL and some useful screenshots and detail where exactly these error occurs. Make sure that you are using the latest version of the theme installed via FTP way, clear all the caches and check the results.

Thanks for the message!

Post count: 10

Hello,

Is there an answer to this question ? I’m working on a template but Cloud Template overrides the_ID() value of the “real” post displayed 🙁

Post count: 4

This is what I ended up doing to resolve the problem.
function properid() {
global $wp;
$url = home_url( $wp->request );
$correct_post_id = url_to_postid( $url );
return $correct_post_id; // returns post id for current post
}

Post count: 10

Thanks for you answer but after thousands of lines read, I believe I found an even better way !

global $tdb_state_single;
$post_id = $tdb_state_single->get_wp_query()->post->ID;

Post count: 104

Thanks! This was what I was looking for, though I wonder if another issue I have is related to have Newspaper template changes the get id.

Post count: 104

I had to go with vexicon solution, though I think this is messy with all the extra calls and look forward to finding a better solution. I think part of the issue is where I am altering the plugins code it runs multiple times and the last Get-ID is always a template, so grabbing URL > ID seems to be the only solution so far.

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