There are also some limitations in the search option, due to some reason to increase the speed of the website. Some users look for tag search within the search bar field, although they have the tag search option available on the search layout.
You can easily search tags within the search bar by simply following the steps mentioned below -
Copy and paste the following code to the "functions.php" file on the currently activated theme -
- add_filter('atbdp_listing_search_query_argument', 'directorist_search_with_tag_on_searchbar');
- function directorist_search_with_tag_on_searchbar($args)
- {
- if (!empty($_GET['q'])) {
- $post_per_page = $args['posts_per_page'];
- $args['posts_per_page'] = -1;
- $has_posts = new WP_Query($args);
- $post_ids = [];
- if ($has_posts->have_posts()) {
- foreach ($has_posts->posts as $post) {
- array_push($post_ids, $post->ID);
- }
- }
- unset($args['s']);
- $args2 = $args;
- $tax_queries = array(
- 'taxonomy' => ATBDP_TAGS,
- 'field' => 'name',
- 'terms' => explode(' ', $_GET['q']),
- );
- $args2['tax_query'] = array(
- 'relation' => 'AND',
- $tax_queries
- );
- $args2['fields'] = 'ids';
- $post_args2 = new WP_Query($args2);
- $posts = !empty($post_args2->have_posts()) ? $post_args2->posts : [];
- $all_ids = array_merge($post_ids, $posts);
- $args['post__in'] = !empty($all_ids) ? $all_ids : array();
- $args['posts_per_page'] = $post_per_page;
- }
- return $args;
- }
This should work like charm.
You can comment below if you need have any questions regarding this.
Enjoy Directorist.
No comments:
Post a Comment