I have some recommendations for your question:
First: stop using query_posts()
. See the codex about this function to see why you shouldn't use it in themes or plugins. Anyway, if you are in a some weird situation where you have not option and you need to use query_posts()
, you should run wp_reset_query()
after the loop. You must know that you are using the global $wp_query
, that contains the original query made by WordPress, and then query_post
that alter the global $wp_query
variable, you end up with unexpected results. Additionally, you are using a deprecated parameter showposts
, replaced by posts_per_page
.
Second: you can use a custom search template (search.php) to customize the look and feel. Just cerate a search.php file in your theme folder and customize it as you want. Don't make custom queries here; if you do that, you are making a new query for posts and wasting the query already done by WordPress. A waste of resources with negative performance impact.
Third: to change the default query parameters used by WordPress, like number of posts per page, etc, you can use pre_get_posts
action.
So, create a your search.php template as you wish and use pre_get_posts
action to say to WordPress what parameters you want to use in the search query:
The search.php template could be something like this:
<?php
get_header();
?>
<div class="wapper">
<div class="contentarea clearfix">
<div class="content">
<h1 class="search-title"> <?php echo $wp_query->found_posts; ?>
<?php _e( 'Search Results Found For', 'locale' ); ?>: "<?php the_search_query(); ?>" </h1>
<?php if ( have_posts() ) { ?>
<ul>
<?php while ( have_posts() ) { the_post(); ?>
<li>
<h3><a href="<?php echo get_permalink(); ?>">
<?php the_title(); ?>
</a></h3>
<?php the_post_thumbnail('medium') ?>
<?php echo substr(get_the_excerpt(), 0,200); ?>
<div class="h-readmore"> <a href="<?php the_permalink(); ?>">Read More</a></div>
</li>
<?php } ?>
</ul>
<?php echo paginate_links(); ?>
<?php } ?>
</div>
</div>
</div>
<?php get_footer(); ?>
And the pre_get_posts
action something like this:
add_action( 'pre_get_posts', function( $query ) {
// Check that it is the query we want to change: front-end search query
if( $query->is_main_query() && ! is_admin() && $query->is_search() ) {
// Change the query parameters
$query->set( 'posts_per_page', 3 );
}
} );