Hey,
How do I get to the post ID as a PHP variable? I've tried in and outside the loop, $thePostID = $post->id; but this doesn't seem to be working. I'm trying to get the post id so I can then call get_post_meta to retrieve the value of a custom field called "filename".
Thanks for any help...
-- hofo
It's $post->ID, not $post->id. Yes, that does matter. Also make sure that if you're doing it from inside a function, that $post is declared as a global variable.
Yeah, like:
function some_func() {
// Works inside of the loop
global $post;
$thePostID = $post->ID;
}
or:
function some_func() {
// Works in single posts outside of the loop
global $wp_query;
$thePostID = $wp_query->post->ID;
}
Thanks!
(!#@#!@#@$%! case sensitive languages, grumble, grumble...)
KnowingArt_com
Member
Posted 1 year ago #