Wordpress - setup_postdata() does not seem to be working?

I could be wrong, but from what I'm seeing, "setup_postdata()" should be used when doing a custom select query (not just query_posts): http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

As well, if you want to use tags like "the_title()" and "the_permalink()" with that custom select query ... you'll need to use the variable name $post specifically (not another variable name) in setup_postdata() - AS WELL - you should call global $post before your "foreach" loop...

So basically follow that example in that codex link. And don't change the variable name $post - otherwise it breaks it.

HTH


Replace the

foreach ( $childPosts as $cp ) : setup_postdata( $cp );

with

foreach ( $childPosts as $post ) : setup_postdata( $post );

So you need to use the exact $post variable along with the setup_postdata().


Depending on where you are using setup_postdata() (if it is not in the main loop, or in a function/sidebar widget, for example), you may also need to declare -

global $post;

Tags:

Get Posts