[resolved] Hierarchical custom post type query return only parent (4 posts)

  1. tighef
    Posted 4 years ago #

    I am using a custom post type of "newsletter" for a Newsletter section of my organization's website. The idea is that each new "newsletter" will be a new edition of our newsletter. The post type is hierarchical, so children of the main "newsletter" will be the articles that the newsletter is comprised of.

    For example, a new "newsletter" might be called "Spring 2010" and it would have children called "Article 1," "Article 2," "Article 3," an so on.

    with a structure resembling this:

    myorganization.org/newsletter/spring-2010/ (this would be the parent "newsletter")
    myorganization.org/newsletter/spring-2010/article1/ (this would be the child of the "newsletter" post)

    I want to make an archive page for the "newsletter" post type, but I only want the main-level or parent posts to show up (I don't want to list individual articles, the children of the "newsletter" posts).

    Is it possible to do a custom query that returns only the parents in a hierarchical custom post type? The closes example I can think of would be something like the wp_list_pages('depth=1'); that sets command, except for a custom post type of "newsletter." I have no problem creating an archive page for all "newsletter" post types, but I can't figure out how to limit it to parent/main-level posts.

    Any help would be much appreciated!

  2. Mark / t31os
    Posted 4 years ago #

    Query for posts(custom posts) with a parent of 0, the only posts(custom posts) with that parent will be top level.

  3. tighef
    Posted 4 years ago #

    Cool, that gave me:

    	'post_type' => 'newsletter',
    	'post_parent' => 0,

    Works like a charm! Thanks!

  4. Mark / t31os
    Posted 4 years ago #

    You're welcome.. ;)

Topic Closed

This topic has been closed to new replies.

About this Topic