I am trying to figure out why my search results are sometimes showing the incorrect number when doing a search.
I think it has something to do with Wordpress searching searching for *both* posts and pages, but only showing posts.
http://www.kimstewart.ca/?s=test&submit.x=0&submit.y=0&submit=Search
From the link above you can see there are 3 Search Results for "test", but only 2 show up...
Here is my code in search.php
<?php include_once($_SERVER['DOCUMENT_ROOT'] . "/inc/php/header.php");
$postnum = 1;
?>
<div id="content">
<div id="content_box">
<div id="content" class="posts">
<?php
//Initialize $pagenum
$pagenum = $paged;
//Set 1st page to 1 instead of 0
if($pagenum == ''){$pagenum = 1;}
//Start checking which page is up
if ($pagenum == 1) {
//On 1st page start counting posts from 1
$postnum = 1;
} else {
//On following pages start counting from 11, 21, 31, etc.
$postnum = ($pagenum * 10) - 9;
}
?>
<?php if (have_posts()) : ?>
<h2 class="archive_head"><?php wp_searchheader()?> Search Results for <em class="grey">"<?php the_search_query(); ?>"</em></h2>
<?php while (have_posts()) : the_post(); ?>
<?php if (is_type_page()) continue; ?>
<div class="postnum"><?php echo $postnum; ?>.</div>
<h2 class="padding"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h2>
<h4 class="padding"><?php the_time('F jS, Y') ?><!-- by <?php the_author() ?> --></h4>
<div class="entry">
<?php // if there's a img in my custom field
if($value !== '') { ?>
<img src="<?php $values = get_post_custom_values("thumbnail"); echo $values[0]; ?>" class="results_thumb" />
<?php } // end if statement
// if there's no img
else { echo 'link of img'; } ?>
<?php the_excerpt() ?>
</div>
<p class="tagged"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?> <strong class="tag">Tags:</strong> <?php the_category(' · ') ?>
<?php $postnum++; ?>
<?php endwhile; ?>
<?php if ($postnum>9) { ?>
<?php include (TEMPLATEPATH . '/navigation.php'); ?>
<?php } ?>
<?php else : ?>
<h2 class="page_header">No Search Results for <em class="grey">"<?php the_search_query(); ?>"</em></h2>
<div class="entry">
<!--<?php include (TEMPLATEPATH . '/searchform.php'); ?>-->
</div>
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
</div>
<?php include_once($_SERVER['DOCUMENT_ROOT'] . "/inc/php/footer.php"); ?>