I'm experiencing some interesting results using
post_parent along with
post_type (local, WP 5.8):
I have a custom post type
'hierarchical' => true) where I'm grabbing all child posts of a parent on a single view using WP_Query.
project while setting
post_parent I get the same results as if I had not set a
post_parent at all: that is, I get all top-level posts with a custom post type of
If I set the
any then I get the correct child posts. I have already checked to make sure that the
$post->ID for the parent is correct (and not 0) and that the posts are all of the same custom post type. I've also double checked the DB for weirdness and verified the parent-child relationships.
To make this stranger, this is on my local; the previous code (setting
post_type) works fine on a live/production site (though that's on an earlier WP version).
This is the query:
$args = array( 'post_type' => 'project', 'post_status' => 'publish', 'post_parent' => $post->ID, 'posts_per_page' => -1, 'orderby' => 'menu_order title', 'order' => 'ASC' ); $projects = new WP_Query( $args ); if( $projects->have_posts() ) : while( $projects->have_posts() ) : $projects->the_post();
As described, if I change to
'post_type' => 'any', then I get the correct child post(s).
What am I missing? Is my data corrupted (though I can't see any evidence of this)...