admin管理员组文章数量:1122832
Currently trying to find only posts that match multiple custom taxonomies however im getting zero posts every time i try. How can i filter these multiple taxonomies using the and relation if some taxonomies will be left blank in the query. I need to be able to get all posts that match the theme health in life sciences at the boston campus for example. This should only return exact matches only
// Start output buffer to capture HTML
ob_start();
$tags = isset($_POST['tags']) ? $_POST['tags'] : array();
$lowercase_terms = array_map('strtolower', $tags);
$trimmed_terms = array_map('trim', $lowercase_terms);
$args = array(
'post_type' => 'nu_institutes',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
);
if (!empty($trimmed_terms)) {
$args['tax_query'] = array(
'relation' => 'AND',
array(
'taxonomy' => 'nu_institutes-tags',
'field' => 'slug',
'terms' => $trimmed_terms,
'operator' => 'IN',
),
array(
'taxonomy' => 'nu_institutes-themes',
'field' => 'slug',
'terms' => $trimmed_terms,
'operator' => 'IN',
),
array(
'taxonomy' => 'nu_institutes-subjects',
'field' => 'slug',
'terms' => $trimmed_terms,
'operator' => 'IN',
),
array(
'taxonomy' => 'nu_institutes-campuses',
'field' => 'slug',
'terms' => $trimmed_terms,
'operator' => 'IN',
),
);
}
$posts_query = new WP_Query($args);
本文标签: filtersHaving trouble querying multiple custom taxonomies
版权声明:本文标题:filters - Having trouble querying multiple custom taxonomies 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300490a1930832.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论