对于不在给定类别子类别中的帖子,您需要进行第二次税务查询。要做到这一点,你需要获得孩子们的身份证。这是可能的get_term_children()
:
$args = [
\'post_type\' => \'post\',
\'post_status\' => \'publish\',
\'posts_per_page\' => $post_number + 1,
\'paged\' => ( get_query_var( \'paged\' ) ) ? get_query_var( \'paged\' ) : 1,
\'tax_query\' => [
[
\'taxonomy\' => $taxonomy,
\'field\' => \'term_id\',
\'terms\' => $category_id,
\'include_children\' => false
],
[
\'taxonomy\' => $taxonomy,
\'field\' => \'term_id\',
\'terms\' => get_term_children( $category_id, $taxonomy ),
\'operator\' => \'NOT IN\'
],
],
];