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?

  • 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 ? – Abdul Awal May 4 '17 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. – Razvan Zamfir May 4 '17 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 – Abdul Awal May 4 '17 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. – Razvan Zamfir May 4 '17 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 ? – Abdul Awal May 4 '17 at 22:05
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>
  • 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 – Razvan Zamfir May 4 '17 at 15:05
  • What if I want to filter results by author? – Razvan Zamfir May 5 '17 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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