• Resolved SimonDukes

    (@simondukes)


    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_posts action that uses is_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.2

    Many thanks

Viewing 1 replies (of 1 total)
  • Thread Starter SimonDukes

    (@simondukes)

    On further investigation it seems that the search plugin we are using was overriding the post_parent 0 setting.

Viewing 1 replies (of 1 total)

The topic ‘CPT hiding child posts issue’ is closed to new replies.