Custom search filter not working
-
Hi,
I have created a custom taxonomy ‘location_tag’ and also added on custom_sql like this.
if (isset($_GET['filter']) && $_GET['filter']) { $filter_ids = array_map('absint', explode(',', $_GET['filter'])); $cat_filter = "INNER JOIN $wpdb->term_relationships AS term_rel ON posts.ID = term_rel.object_id INNER JOIN $wpdb->term_taxonomy AS term_tax ON term_rel.term_taxonomy_id = term_tax.term_taxonomy_id AND term_tax.taxonomy = 'wpsl_store_category' AND term_tax.term_id IN (" . implode(',', $filter_ids) . ")"; } else { $cat_filter = ''; } // Get location tag ID if (isset($_GET['tag_filter']) && $_GET['tag_filter']) { $filter_tagids = array_map('absint', explode(',', $_GET['tag_filter'])); $tag_filter = "INNER JOIN $wpdb->term_relationships AS term_rel ON posts.ID = term_rel.object_id INNER JOIN $wpdb->term_taxonomy AS term_tax ON term_rel.term_taxonomy_id = term_tax.term_taxonomy_id AND term_tax.taxonomy = 'location_tag' AND term_tax.term_id IN (" . implode(',', $filter_tagids) . ")"; } else { $tag_filter = ''; } // The default query that selects store location that fall within the selected radius. $sql = "SELECT post_lat.meta_value AS lat, post_lng.meta_value AS lng, posts.ID, ( %d * acos( cos( radians( %s ) ) * cos( radians( post_lat.meta_value ) ) * cos( radians( post_lng.meta_value ) - radians( %s ) ) + sin( radians( %s ) ) * sin( radians( post_lat.meta_value ) ) ) ) AS distance FROM $wpdb->posts AS posts INNER JOIN $wpdb->postmeta AS post_lat ON post_lat.post_id = posts.ID AND post_lat.meta_key = 'wpsl_lat' INNER JOIN $wpdb->postmeta AS post_lng ON post_lng.post_id = posts.ID AND post_lng.meta_key = 'wpsl_lng' $cat_filter $tag_filter WHERE posts.post_type = 'wpsl_stores' AND posts.post_status = 'publish' $sql_sort"; return $sql; }
It works fine when I search either using default categories or filter using custom taxonomy I created. But it gives no result when I select option from both and search.
I attached screenshot if it helps
https://tinyurl.com/2ecacofnThank you
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Custom search filter not working’ is closed to new replies.