Okay
  Public Ticket #2233084
Excluding certain/custom post types from search results.
Closed

Comments

  • SeizeTheBeat started the conversation

    I hate submitting so many tickets, but I have another question 😂

    Is there any way for me to exclude custom post types from search results?

    The search function is vital on my website, but it includes the posts from my plugin Wordpress Download Manager. I don't want those results shown...is there any way to disable that post type in the search results?

    (Made this ticket public, because I couldn't find any results for it, and it might help someone else out)

  •  3,023
    Andrew replied

    Hey there,

    It's not possible to limit the search post types from the theme options. The options does not exist.

    You can try and modify the search.php file to only search the items you need.

    This is a bit outside our scope of support.

    The search query is on line 42 on search.php file. We are assuming you are using the latest version of the theme 11.0.1

    The search results are in $wp_query line 44 The loop to show the posts starts on line 70

    Try configuring this plugin and check: https://wordpress.org/plugins/search-everything/ . 

    Hope this helps. 


    Best

  • SeizeTheBeat replied

    Ok,

    I am going to leave this here for anyone who has this problem (let me know if I'm breaking any rules or anything by posting this).


    I installed the "My Custom Functions" plugin (You could this in the functions.php, but this plugin keeps this regardless of updates and changes - and easy to deactivate if you break anything).

    Then I added this code to it:

    function shapeSpace_filter_search($query) {
        if (!$query->is_admin && $query->is_search) {
            $query->set('post_type', array('post', 'page', 'book'));
        }
        return $query;
    }
    add_filter('pre_get_posts', 'shapeSpace_filter_search');

    'post', 'page', 'book'

    Are all the post types I want to allow. You can add as many as you need, and it should support custom post types (as long as you have the right post type). Anything not included will be excluded.

    This ticket can be marked as solved, or closed. Thank you :)