Dave's WordPress Live Search
restrict results to a custom post type (7 posts)

  1. jlamerto
    Posted 4 years ago #

    I'm having difficulty coming up with a way to get the live search to restrict results to a custom post type "product" and am hoping someone could help.

    I'm using a hidden field in the search form generated in a specific product template to set the post type as suggested else where in the forums e.g....
    <input type="hidden" name="post_type" value="product" />

    Which seems to work well for the form submit results (via Relevanssi) but not so for the live search popup results.

    Does anyone know how I can achieve this?


  2. Dave Ross
    Plugin Author

    Posted 4 years ago #

    The latest beta of version 3.0 should pass all your hidden parameters on to WP_Query. The 2.x versions just cared about language selection.

  3. marusic
    Posted 4 years ago #

    3.0a1 and 3.0a2 don't pass the hidden parameters. Can you post a version that does somewhere, or an example that works?

  4. trolol
    Posted 3 years ago #

    I am actually looking for similar functionality, which I can't seem to figure out how to do. I've managed to restrict the live search results to a single post_type by editing DavesWordPressLiveSearchResults.php line 69:
    $wpQueryParams['post_type'] = 'any';
    If you change 'any' to your desired post_type, it'll work.

    My problem is with getting 2 post_types to work, for example 'post' AND 'custom', and I had no success with defining that properly (my knowledge in PHP is very limited). Would anyone be kind enough to provide a fix for this (even though it's hard code and prone to get messed up with future updates)?


  5. faeronsayn
    Posted 3 years ago #

    Could you possible use an array to assign the values of the post types?

    I haven't tested this though.

  6. larryhans
    Posted 3 years ago #

    To get only the products from woocommerce:
    $wpQueryParams['post_type'] = 'products';

    It worked pretty fine for us.

  7. lmoore11608
    Posted 3 years ago #

    using $wpQueryParams['post_type'] = 'products';
    didn't give me any dropdown results. The loading circle popped up, but nothing came up for the live search. It only worked for me with $wpQueryParams['post_type'] = 'any';

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Dave's WordPress Live Search
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic