WordPress : How to have query search posts only


If you need to have your WordPress search only search posts for results, you can insert this code before the ‘if(have_posts()):’ line on search.php and it will do that for you.

// search only posts
global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => 'post' ) );
query_posts( $args ); 

Further to that you can add any arguments from the standard WP_Query function to there to make the search more custom :)

Leave a Comment

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>