Tagged: 

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #17293
    Thelma
    Member

    Sakin-

    Is there a way to exclude some or all posts from appearing in a search result?

    Thanks.

    #17299
    Sakin
    Keymaster

    @fcharvet: I don’t get it what are you trying to do it. Why do you want to exclude posts from search. Search is added to search posts.

    #17481
    Thelma
    Member

    Sakin:

    Site: http://www.mitchell-engineering.com

    All our information is contained within Pages; we don’t have or use Posts. The only posts that exist were created to allow the featured post slider, but they do not contain any information. Yet, they will appear in a search result if the search phrase matches (or contains) the post’s name.

    A workaround that I’m currently using is to use ‘Images Slider’ as the type of slider for the Featured Slider, and then edit the Status of all Posts from Published to Draft.

    But, is there a more general way to exclude Posts from a search?

    Thanks.

    #17489
    Sakin
    Keymaster

    @fcharvet: The simple way is to just remove the post when you are using Image Slider. But if you want then it’s bit complicated. You need to build child theme and then crate functions.php file in your child theme and add the following code.

    <?php
    /**
     * Only Pages in Search
     */
    function catcheverst_child_search_pages($query) {
        if ( !is_admin() && $query->is_main_query() ) {
            if ($query->is_search) {
    			$query->set( 'post_type', 'page' );
            }
        }
    }
    add_action( 'pre_get_posts', 'catcheverst_child_search_pages' );
    #17499
    Thelma
    Member

    Sakin: Building child themes and creating functions = more time. If there is no downside to simply changing the status of posts from ‘Published’ to ‘Draft’ in order for them not to show up in a search, then I’ll stay with my method … for now. Thanks for your reply.

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Excludes Posts From Searches’ is closed to new replies.