Query to Exclude Child Pages from Custom Post Type Archive
I have a hierarchical custom post type called Services. On the Services archive page I want to display only parent Services and exclude child Services.
I found similar answers to my question, which is to customize the main query within archive-services.php using the following:
function exclude_children( $query ) {
if ( $query-is_main_query() !is_admin() $query-is_post_type_archive( 'services' ) ) {
$query-set( 'post_parent', 0 );
}
}
add_action( 'pre_get_posts', 'exclude_children' );
But the child services are still displayed. Why doesn't this work?
Topic children pre-get-posts wp-query custom-post-types Wordpress
Category Web