This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

conflict two searches on the same screen

Home Forums Product Support Forums Ajax Search Pro for WordPress Support conflict two searches on the same screen

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #24563
    essenciadigital74essenciadigital74
    Participant

    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 post`s 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.

    #24573
    Ernest MarcinkoErnest Marcinko
    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;
    }
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.