Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('atbdp_listing_search_query_argument', 'pfm_directorist_updated_args_for_searchbar');
- function pfm_directorist_updated_args_for_searchbar($args)
- {
- if (isset($_GET['q']) && !empty($_GET['q'])) :
- $post_per_page = $args['posts_per_page'];
- $args['posts_per_page'] = -1;
- $args1 = $args;
- $args1['fields'] = 'ids';
- $post_args1 = new WP_Query($args1);
- $posts1 = !empty($post_args1->have_posts()) ? $post_args1->posts : [];
- unset($args['s']);
- $args2 = $args;
- $args2['tax_query'] = array(
- array(
- 'taxonomy' => ATBDP_LOCATION,
- 'field' => 'name',
- 'terms' => explode(' ', $_GET['q']),
- 'include_children' => 1
- )
- );
- $args2['fields'] = 'ids';
- $post_args2 = new WP_Query($args2);
- $posts2 = !empty($post_args2->have_posts()) ? $post_args2->posts : [];
- $all_ids = array_merge($posts2, $posts1);
- if (!empty($all_ids)) {
- $args['post__in'] = $all_ids;
- } else {
- $args['s'] = $_GET['q'];
- }
- $args['posts_per_page'] = $post_per_page;
- endif;
- return $args;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement