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
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745583163a4634373.html
$children
before merging$children
with$posts
– mrben522 Commented Apr 16, 2019 at 16:14