admin管理员组文章数量:1406950
I need to search properties by cities and areas at the same time. So I created two query to take all the references of the cities, and the areas:
$city_query = "SELECT *
FROM $wpdb->terms t
INNER JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id
WHERE tt.taxonomy = 'property-city' AND LOWER(t.name) LIKE '%s' ";
$like = '%colorado%';
$result = $wpdb->get_results($wpdb->prepare($city_query, $like), OBJECT);
$city_ids = array();
foreach($result as $city)
{
array_push($city_ids, $city->term_id);
}
$area_query = "SELECT *
FROM $wpdb->terms t
INNER JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id
WHERE tt.taxonomy = 'property-area' AND LOWER(t.name) LIKE '%s' ";
$result = $wpdb->get_results($wpdb->prepare($area_query, $like), OBJECT);
$area_ids = array();
foreach($result as $area)
{
array_push($area_ids, $area->term_id);
}
until here there is no problem 'cause I taken only the reference of the taxonomies. The problem is here:
$args = array(
'post_type' => 'zoacres-property',
'post_status' => 'publish',
'posts_per_page' => 12,
'order' => 'DESC',
'paged' => 1,
'tax_query' => array(
array(
'taxonomy' => 'property-city',
'field' => 'term_id',
'terms' => $city_ids,
'operator' => 'IN',
),
array(
'taxonomy' => 'property-area',
'field' => 'term_id',
'terms' => $area_ids,
'operator' => 'IN',
)
)
);
$query = new WP_Query($args);
$found_posts = $query->found_posts;
Essentially, this query isn't returning anything 'cause there are no properties for colorado
which have as taxonomy
area, but there are only properties in city taxonomy.
Is it possible to return the results that there are at least in a taxonomy, but searching for all of them?
本文标签: custom taxonomyHow to join result of different taxonomies
版权声明:本文标题:custom taxonomy - How to join result of different taxonomies? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744948647a2633942.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论