Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › conflict two searches on the same screen
This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko 3 years, 7 months ago.
- AuthorPosts
- November 7, 2019 at 7:45 pm #24563
Hi!
I have a question.
Your plugin, Ajax Search Pro is awesome and it helps me a lot, but in a specific case it does not work for me.
The case: I have one search at the navbar and it searches everything inside the site. At the same time when I am reading a post there is another search bar which just find contents inside posts category.
The problem: In the home page the navbar search works great but when I am in the post page the navbar search just find posts related to a category.
Is that a bug or a normal behavior?
Thank you.November 8, 2019 at 10:06 am #24573Hi!
I assume you are using some sort of a custom code to achieve the search within the current post category? (as this is not possible via settings only)
In case you are using this knowledge base code, you will have to extend it to only apply on a given search ID, such as:
Best,add_filter( 'asp_query_args', 'asp_posts_from_same_cat', 10, 2 ); function asp_posts_from_same_cat($args, $search_id) { $categories = wp_get_post_categories( $args['_page_id'] ); $apply_to_search_id = 1; // Change this to the search ID you need if ( !is_wp_error($categories) && count($categories) && $search_id == $apply_to_search_id ) { $args['post_tax_filter'][] = array( 'taxonomy' => 'category', // taxonomy name 'include' => $categories, // array of taxonomy term IDs to include 'exclude' => array(), 'allow_empty' => false // allow (empty) items with no connection to any of the taxonomy terms filter ); } return $args; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.