Skip to main content
1 of 2
fuxia
  • 107.1k
  • 38
  • 255
  • 459

When a post (of ony type) is a child, its property post_parent is a number with the parent’s post ID. Posts without a parent have a value 0 instead. So you can test this value:

if ( 0 !== (int) $post->post_parent )
{
    // show the post
}     

Another option is a filter on pre_get_posts (not tested, just an idea):

add_action( 'pre_get_posts','hide_children' );

function hide_children( $query ) 
{
    remove_action( 'pre_get_posts', current_filter() );

    if ( is_admin() or ! $query->is_main_query() ) 
        return;

    if ( ! $query->is_post_type_archive( 'your_post_type_name' ) )
        return;

    // only top level posts
    $query->set( 'post_parent', 0 );
}
fuxia
  • 107.1k
  • 38
  • 255
  • 459