Search Results Not Displaying Correct Number of Results
-
I put in a code to display the number of results for searches matching the users query and the count is only displaying the exact number of posts in all and not based on the search query. How do I get it to show the number of results found for the search query. I am using a custom search form where it searches by multiple tags the user selects.
Here’s the search.php code
<?php global $query_string; $query_args = explode("&", $query_string); $search_query = array(); foreach($query_args as $key => $string) { $query_split = explode("=", $string); $search_query[$query_split[0]] = urldecode($query_split[1]); } // foreach $search = new WP_Query($search_query); ?> <?php get_header(); ?> <div class="row"> <div class="excerpt left-home"> <h1 class="arh">Your Search Returned <?php /* Search Count */ $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; _e(''); _e('<span class="search-terms">'); echo $key; _e('</span>'); _e(' — '); echo $count . ' '; _e('Anime Titles'); wp_reset_query(); ?></h1> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h2 class="title-excerpt"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2> <div class="entry"> <?php the_post_thumbnail('thumbnail', array('class' => 'alignleft')); ?> <?php the_excerpt(); ?> <div class="clearfix"></div> </div> <div class="postinfo"> <?php _e('Category: ', 'amdhas'); the_category(', ') ?> | <?php if (get_the_tags()) the_tags(__('Tags: ', 'amdhas'), ', '); ?> </div> </div> <?php endwhile; ?> <?php previous_posts_link(); ?> <?php next_posts_link(); ?> <?php else : ?> <div class="entry"> <p> <?php _e('No matches. Please try again, or use the navigation menus to find what you search for.', 'amdhas'); ?> </p> </div> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_template_part( 'footer', 'content' ); ?> <?php get_footer(); ?>
- The topic ‘Search Results Not Displaying Correct Number of Results’ is closed to new replies.