我正在尝试显示自定义帖子类型的孙子。
结构相当简单:
Issues
Issue 1
Article 1
Article 2
Article 3 etc
Issue 2
Article 1
Article 2
Article 3 etc
Issue 3 etc etc
是否有办法在指定ParentID的单个WP查询中显示文章(孙子)?
//displays all posts :(
$args = array(\'post_type\' => \'magazine\',
\'child_of\' => array(20321), //Issues (parent postID)
);
SO网友:ianhman
在进一步研究和测试后解决了我自己的问题:)最终使用了两个查询将结果从一个查询传递到另一个查询。希望这对别人有帮助。
$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