Get Custom Post Types included in Search Results

Hi,

I want the wp search results to look though my vendors which I created as a new custom post_type vendor. How do I do this. It`s not working.

  • Milan

    Hello Luc

    Hope you are well today and thanks for asking us. :slight_smile:

    First of all check that you have not set "True" to Exclude From Search setting of custom post type in CustomPress. Please take a look at this screenshot.

    If you have kept it for some other reason and still want to include your post type in search result, please use this snippet to do so,

    function filter_search($query) {
        if ($query->is_search) {
    	$query->set('post_type', array('YOUR_CUSTOM_POST_TYPE_1', 'YOUR_CUSTOM_POST_TYPE_2'));
        };
        return $query;
    };
    add_filter('pre_get_posts', 'filter_search');

    Replace YOUR_CUSTOM_POST_TYPE_1 & YOUR_CUSTOM_POST_TYPE_2 with the slugs of your custom post type. You can find slugs of your custom post types on CustomPress > Content Types > Post Types. Please take a look at this screenshot.

    Let me know how it goes.
    Cheers,
    Milan

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.