How to display the number of search results found (redux)
-
In response to this older topic:
https://www.ads-software.com/support/topic/60377These solutions seem a little convoluted. Why not just use $wp_query->post_count and save a database call?
I’ve also added a small piece of Javascript to forward the user to a post if there is only one result. Pretty useful, but there might be a better way of doing this.
Here is the code for the top of my search template:
<?php $num = $wp_query->post_count; if (have_posts()) : ?> <h2><?php echo $num; ?> Entries Found</h2> <?php while (have_posts()) : the_post(); if ($num == 1) { ?><script language="Javascript">document.location.href='<?php echo get_permalink($id); ?>';</script><?php } ?>
Viewing 10 replies - 1 through 10 (of 10 total)
Viewing 10 replies - 1 through 10 (of 10 total)
- The topic ‘How to display the number of search results found (redux)’ is closed to new replies.