您需要使用tax_query
具有WP_Query
. 使用tax_query
, 默认情况下,子术语包括在要设置的术语中。下面是一个例子-
$args = array(
\'post_type\' => \'post\', // Your post type
\'orderby\' => \'meta_value_num\',
\'meta_key\' => \'rankk\',
\'order\' => \'DESC\',
\'posts_per_page\' => 100,
\'tax_query\' => array(
array(
\'taxonomy\' => \'category\', // Taxonomy name
\'field\' => \'term_id\', // Means you\'ll use term id to determine your parent term.
\'include_children\' => true,
\'operator\' => \'IN\'
\'terms\' => \'YOUR PARENT CATEGORY ID\', // Your term or category ID
),
),
);
$q = new WP_Query( $args );
if ( $q->have_posts() ) {
while ( $q->have_posts() ) {
$q->the_post();
the_title();
}
wp_reset_postdata();
}
希望以上内容有所帮助。