Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › conflict two searches on the same screen › Reply To: conflict two searches on the same screen
November 8, 2019 at 10:06 am
#24573
Keymaster
Hi!
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:
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;
}