我对编码很陌生。下面的代码运行良好,它显示了具有分类“persons”的帖子,但当我使用第二部分时,它没有显示内容。我想展示的是一篇有人和动物分类学术语的文章。
$terms = wp_get_post_terms( $post->ID, \'persons\' );
$term_slugs = wp_list_pluck( $terms, \'slug\' );
\'tax_query\' => array(
array(
\'taxonomy\' => \'persons\',
\'field\' => \'id\',
\'terms\' => $term_slugs
)
),
第二部分:
$terms = wp_get_post_terms( $post->ID, \'persons\' );
$term_slugs = wp_list_pluck( $terms, \'slug\' );
$terms2 = wp_get_post_terms( $post->ID, \'animal\' );
$term_slugs2 = wp_list_pluck( $terms, \'slug\' );
\'tax_query\' => array(
array(
\'taxonomy\' => \'persons\',
\'field\' => \'id\',
\'terms\' => $term_slugs
),
array(
\'taxonomy\' => \'animal\',
\'field\' => \'id\',
\'terms\' => $term_slugs2
)
),
最合适的回答,由SO网友:bdtheme 整理而成
请改用此代码。
$terms = wp_get_post_terms( $post->ID, array(\'competition\', \'session\') );
$term_slugs = wp_list_pluck( $terms, \'slug\' );
$season = wp_get_post_terms( $post->ID, \'session\' );
$season_slugs = wp_list_pluck( $terms, \'slug\' );
$args = array(
\'post_type\' => array( \'football_fixture\' ), // profile and letter are CPTs
\'tax_query\' => array(
array(
\'taxonomy\' => \'competition\',
\'field\' => \'slug\',
\'terms\' => $term_slugs
),
array (
\'taxonomy\' => \'session\',
\'terms\' => $season_slugs,
\'field\' => \'slug\')
)
);
$my_query = new WP_Query($args);