我认为非常有帮助的用户给了你一个错误的答案。下面是一个我认为更好的例子:
//The ID of the parent page, for example 4. Change to the correct ID.
//For example, if you are in the page loop, you can use get_the_ID() to get ID of current page
$parent_id = 4;
//The terms that the page belongs to.
$terms = array( \'one_term\', \'another_term\' );
$args = array(
\'post_type\' => \'page\',
\'post_parent\' => $parent_id,
\'tax_query\' => array(
array(
\'taxonomy\' => \'top5\',
\'field\' => \'name\',
\'terms\' => $terms
)
)
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
//Start the loop
while ( $query->have_posts() ) {
$query->the_post();
//Do whatever you want with the found pages. For example:
the_title();
if( has_post_thumbnail() ) {
the_post_thumbnail();
}
the_content();
}
//End the loop
wp_reset_postdata();
} else {
//Do something if pages have not been found
}
注意:默认情况下,“pages”没有分类法,因此我假设您已经为“pages”帖子类型注册了“top5”分类法。另外,您说您想要获取页面的摘录,默认情况下,页面不支持摘录,因此我假设您添加了对页面的摘录支持。