wp query - How to display grandchildren only of custom post?

I am trying to display the grandchildren of a custom post type.The structure is is fairly simple:IssuesIssue 1Article 1A

I am trying to display the grandchildren of a custom post type.

The structure is is fairly simple:

Issues
   Issue 1
      Article 1
      Article 2
      Article 3 etc
   Issue 2
      Article 1
      Article 2
      Article 3 etc
   Issue 3 etc etc

Is there a way to display the Articles(grandchildren) in a single WP query specifying the ParentID?

    //displays all posts :(
    $args = array('post_type' => 'magazine',
        'child_of' => array(20321), //Issues (parent postID)
    );

I am trying to display the grandchildren of a custom post type.

The structure is is fairly simple:

Issues
   Issue 1
      Article 1
      Article 2
      Article 3 etc
   Issue 2
      Article 1
      Article 2
      Article 3 etc
   Issue 3 etc etc

Is there a way to display the Articles(grandchildren) in a single WP query specifying the ParentID?

    //displays all posts :(
    $args = array('post_type' => 'magazine',
        'child_of' => array(20321), //Issues (parent postID)
    );
Share Improve this question asked Apr 16, 2019 at 14:47 ianhmanianhman 135 bronze badges 3
  • Check this out: wordpress.stackexchange/questions/81645/… – Siddhesh Shirodkar Commented Apr 16, 2019 at 15:11
  • @SiddheshShirodkar that displays children and grandchildren. I only want to display the grandchildren. – ianhman Commented Apr 16, 2019 at 15:16
  • All you would have to do to make that grandchildren only is return $children before merging $children with $posts – mrben522 Commented Apr 16, 2019 at 16:14
Add a comment  | 

1 Answer 1

Reset to default 0

Solved my own question after further research and testing :) Ended up using 2 queries passing the result from one query to the other. Hope this helps someone.

    $argsIssues = array( 'post_type' => 'magazine',
        'post_parent__in' => array(20321), //get issue(children) posts from the issues(parent)
        'fields' => 'ids' //query only the postIDs
    );
    $q = get_posts( $argsIssues ); //run $argsIssues query

    $argsArticles = array( 'post_type' => 'magazine',
        'post_parent__in' => $q //get article(grandchildren) posts from issue(children) posts.
    );

    query_posts( $argsArticles ); //run $argsArticles query

    //while loop goes here to display posts from $argsArticles query

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745583163a4634373.html

相关推荐

  • wp query - How to display grandchildren only of custom post?

    I am trying to display the grandchildren of a custom post type.The structure is is fairly simple:IssuesIssue 1Article 1A

    10小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信