CPT hiding child posts issue
-
Hi, I have two custom post type (artisan and exhibit) which both have both parent and child posts. On the artisan archive template I only want to display the parent posts. Nothing seems to work limit the artisans to only parent posts. I’ve added a
pre_get_postsaction that usesis_post_type_archive( 'artisan' )and$query->set( 'post_parent', 0 )to limit the child posts. The CPT is set to Hierarchical and has Supports -> Page Attributes turned on.Here is the code:
function exclude_artisan_children( $query ) {
if ( $query->is_main_query() && !is_admin() && is_post_type_archive( 'artisan' ) ) {
$query->set( 'post_parent', 0 );
}
}
add_action( 'pre_get_posts', 'exclude_artisan_children' );From the documentation of both of Pods and WP this should work.
Should be using a different approach/code to limit to only parent posts?
Running Pods 3.3.2Many thanks
The topic ‘CPT hiding child posts issue’ is closed to new replies.