admin管理员组文章数量:1431720
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
|
1 Answer
Reset to default 0Solved 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
本文标签: wp queryHow to display grandchildren only of custom post
版权声明:本文标题:wp query - How to display grandchildren only of custom post? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745583162a2664739.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$children
before merging$children
with$posts
– mrben522 Commented Apr 16, 2019 at 16:14