• George

    (@quantum_leap)


    I am using Relevanssi and SearchWP Live Ajax Search. I am restricting search results to a particular custom post type through Relevanssi but when combined with SearchWP Live Ajax Search the results return everything. Is there a way to filter that out from SearchWP Live Ajax Search?

    • This topic was modified 6 years, 10 months ago by George.
Viewing 4 replies - 1 through 4 (of 4 total)
  • You can add a hidden input to your searchform.php (if you have one) to limit the results. Worked for me, without Relevanssi though.

    <input type="hidden" name="post_type" value="your-cpt-slug">

    Check here in the WP Code Reference

    @ngp13, do you have installed plugin “SearchWP Live Ajax Search” and no submit button?

    Additional <input type="hidden" ... in searchform.php doesnt limit results by post type for me!

    Yes, i have the “SearchWP Live Ajax Search” plugin installed and it returns results without a submit button. In my searchform.php form i have an additional input like this:

    <input type="hidden" name="post_type" value="book">

    Where “book” is the slug of my Custom Post Type.

    @ngp13, thanks for answer!

    Dut it doesnt work for me.

    I solved the issue by adding in functions.php:

      add_filter('searchwp_live_search_query_args', 'filter_live_search', 999);
      function filter_live_search( $args ) {
         $args['post_type'] = 'hotel'; 
        return $args;
      }

    “hotel” is the slug of my Custom Post Type.

    source: https://github.com/jchristopher/searchwp-live-ajax-search/issues/86

    • This reply was modified 6 years, 4 months ago by Sonika.
    • This reply was modified 6 years, 4 months ago by Sonika.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Way to restric search to a particular custom post type?’ is closed to new replies.