0

I have a custom posts (called "radio-shows") on which I wish to display posts from a certain category but only if they are children of the custom posts page.

So far I have managed to display all posts in the category:

<ul class="podcasts">
  <?php $catquery = new WP_Query( 'cat=7&posts_per_page=30&order=DESC' );
    while($catquery->have_posts()) : $catquery->the_post();
  ?>
    <li class="track-list-item"><?php the_content();?></li>
  <?php endwhile;?>
</ul>

What can I add to the code above to make it display, on each custom post page, only its child posts?

7
  • Your question is little confusing to me. Is custom post type radio-shows hierarchical like default page post type ? And you want to display only child items when user is on a radio show page ? or something else ? May 4, 2017 at 18:14
  • I want to display child items when user is on a radio show page like urban sunsets radio show. There is an archive-radio-show.php page if that is what you mean by hierarchical. May 4, 2017 at 18:43
  • Do you have the following dropdown (prntscr.com/f459oc) on edit page of radio show ? This is what I mean by hierarchical May 4, 2017 at 18:48
  • I don't have the dropdown. It is a post, not a page. I used the Toolset Types plugin to create the custom posts and their custom fields. May 4, 2017 at 19:53
  • So how do you assign child items ? I have no idea what you're trying to achieve. Are you using any custom taxonomy connected to the post type or whatever else you're using to understand child/parent items ? May 4, 2017 at 22:05

1 Answer 1

0

You can use the post_parent argument for the query. Here is a slightly modified version of your code:

<ul class="podcasts">
    <?php 
    global $post;
    $catquery = new WP_Query( 'cat=7&posts_per_page=30&order=DESC&post_parent=' . $post->ID );
    while($catquery->have_posts()) : $catquery->the_post();?>
        <li class="track-list-item"><?php the_content();?></li>
    <?php 
    endwhile; wp_reset_postdata(); 
    ?>
</ul>
2
  • Well, it looked promising so I tried it ot and now the page does not display anithing. Could this be because it is a custom post (radio-show)? The template is content-show.php May 4, 2017 at 15:05
  • What if I want to filter results by author? May 5, 2017 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.