Tagged: search
- This topic has 4 replies, 2 voices, and was last updated 10 years, 5 months ago by Thelma.
-
AuthorPosts
-
November 15, 2013 at 11:37 pm #17293ThelmaMember
Sakin-
Is there a way to exclude some or all posts from appearing in a search result?
Thanks.
November 16, 2013 at 1:31 am #17299SakinKeymaster@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.
November 22, 2013 at 12:12 am #17481ThelmaMemberSakin:
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.
November 22, 2013 at 12:42 am #17489SakinKeymaster@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' );
November 22, 2013 at 1:17 am #17499ThelmaMemberSakin: 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.
-
AuthorPosts
- The topic ‘Excludes Posts From Searches’ is closed to new replies.