Tag: wp_query

Better Search Results Counts in WordPress

I recently stumbled on the following snippet of code in your average WordPress theme: <?php if ( is_home() ) : ?> <h2><?php echo the_title(); ?></h2> <?php elseif ( is_search() ): ?> <h1><?php $search_count = 0; $search = new WP_Query(“s=$s&showposts=-1”); if($search->have_posts()) { while($search->have_posts()) { $search->the_post(); $search_count++; } } echo $search_count; ?> <?php _e(‘Search results’); ?></h1> <?php […]

Posted: December 31, 2013