I want to use the wordpress search function but I want it to only search my blog posts and exclude my static pages from the query. How to do this? I am not opposed to using a plugin.
The easiest way to limit search to specific post types in WordPress is to use a plugin like SearchWP. SearchWP is the best WordPress search plugin on the market, with over 30,000 active installs. Using it, you can limit search on your site to specific post types in just a few clicks, no coding needed.
The easiest way to customize your WordPress search results page is to use a plugin like SearchWP. This is a flexible and easy-to-use plugin designed to improve WordPress search on your website. After the installation, you'll get full control over how search works on your site and can easily customize it.
WP Extended Search You can simply go to the plugin settings and select the options that you want to include in the search. You can search in author name, taxonomies, post types, meta data, and more. The plugin extends the default WordPress search so you don't need to add any shortcode or widget.
Answer is here
http://www.shilling.id.au/2011/06/23/wordpress-search-only-show-post-and-not-pages/
<?php
function SearchFilter($query) {
if ($query->is_search) {
$query->set('post_type', 'post');
}
return $query;
}
add_filter('pre_get_posts','SearchFilter');
?>
Simply add <input type="hidden" name="post_type" value="post" />
to the theme search form... regards!
This solution makes the search retrieve only posts if you haven't specified a different post type. This method wont interfere if you specify a custom post type in a hidden field in a different search field.
function searchFilter($query) {
if ($query->is_search) {
if ( !isset($query->query_vars['post_type']) ) {
$query->set('post_type', 'post');
}
}
return $query;
}
add_filter('pre_get_posts','searchFilter');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With