Products
GG网络技术分享 2025-03-18 16:12 4
I\'m using a theme template and when i try to get post ID it returns the ID of the template not the ID of the actual single post.
the template ID is: 215
the post ID is: 1911
the following code will only output 215function 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\'.
I\'ve contacted support with the theme authors on this topic as well but for the time being i\'ve found a way to work around it.
function metavalue() {global $wp;
$url = home_url( $wp->request );
$correct_post_id = url_to_postid( $url );
$meta = get_post_meta($correct_post_id, \'product_url\', true);
return $meta;
}
add_shortcode(\'url_short\', \'metavalue\');
Demand feedback