Simply get all terms first: 这里我使用属性自定义帖子类型作为示例
$property_statu_terms = wp_get_post_terms( $post->ID, \'property_status\', array( \'fields\' => \'ids\' ));
$property_type_terms = wp_get_post_terms( $post->ID, \'property_type\', array( \'fields\' => \'ids\' ));
$property_city_terms = wp_get_post_terms( $post->ID, \'property_city\', array( \'fields\' => \'ids\' ));
$property_state_terms = wp_get_post_terms( $post->ID, \'property_state\', array( \'fields\' => \'ids\' ));
$property_feature_terms = wp_get_post_terms( $post->ID, \'property_feature\', array( \'fields\' => \'ids\' ));
使用
relation
[OR] or [AND] 获得你想要的职位。
$query = new WP_Query( array(
\'post_type\' => \'property\',
\'posts_per_page\' => 3,
\'orderby\' => \'rand\',
\'post__not_in\' => array( $post->ID ),
\'ignore_sticky_posts\' => 1,
\'tax_query\' => array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'property_status\',
\'field\' => \'id\',
\'terms\' => $property_statu_terms,
),
array(
\'taxonomy\' => \'property_type\',
\'field\' => \'id\',
\'terms\' => $property_type_terms,
),
array(
\'taxonomy\' => \'property_city\',
\'field\' => \'id\',
\'terms\' => $property_city_terms,
),
array(
\'taxonomy\' => \'property_state\',
\'field\' => \'id\',
\'terms\' => $property_state_terms,
),
array(
\'taxonomy\' => \'property_feature\',
\'field\' => \'id\',
\'terms\' => $property_feature_terms,
),
),
));