[wp-hackers] problem with $post->post_parent

Will Anderson will at itsananderson.com
Tue Mar 30 01:56:50 UTC 2010


Inside the checkPostID function, you're using $post, but you never declare
it as a global, so it will be null. Try this and see what happens

function checkPostID() {
   global $wp_query, $post; // global $post as well
   $thePostID = $wp_query->post->ID;
   $myParent = $post->post_parent;
   echo "i am post ". $thePostID . " and my parent is " . $myParent;
}

If this code is being executed before the $post variable is populated, it
will still not contain the post parent.


More information about the wp-hackers mailing list