用于获取由2个不同分类法中的2个不同术语筛选的自定义帖子类型帖子的自定义查询将是:
$args = array(
\'post_type\' => \'listing\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'job_listing_region\',
\'field\' => \'slug\',
\'terms\' => \'himalyan\', // this can be an array of terms also
),
array(
\'taxonomy\' => \'job_listing_category\',
\'field\' => \'slug\',
\'terms\' => \'shop\', // this can be an array of terms also
),
),
);
$query = new WP_Query( $args );
调整
tax_query
您需要的值,例如,通过从URL获取的$变量传递“术语”,例如:
$region = get_query_var(\'job_listing_region\');
$args = array(
...
\'terms\' => $region;
...
);
此外,通读
Template Hierarchy 文档中,您应该使用自定义帖子类型/自定义分类模板,并使用
pre_get_posts
筛选以调整查询。