Search results : only one result shows up
-
I have the following problem. When I get one result of a searchquery, it shows one correct result, but when I try to loop the results – it just loops all posts.
I use a highly customized shaken-grid-free template. In the header I inserted a searchform like this:
<form id="searchform" name="searchform" method="get" action="<?php echo home_url(); ?>"> <div> <input type="text" id="s" name="s" class="sfield" value="type your search query here" onfocus="if(this.value == 'type your search query here') { this.value = ''; }" /> <input type="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search'); ?>" class="doSearch"/> </div> </form>
To collect the results I have this code, which works for one result, but how do I loop the results? When I use this:
<?php while (have_posts()) : the_post(); ?>
It will just show random posts.<?php /* If there are no posts to display, such as an empty archive page */ ?> <?php if (have_posts()) : ?> <?php #$my_query = new WP_Query('posts_per_page=2'); ?> <?php wp_reset_postdata(); // reset the query ?> <?php echo "Quotes with ". $_GET['s']; ?> <?php #while ($my_query->have_posts()) : $my_query->the_post(); ?> <?php #while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <center> <div class="boxxy"> <?php if ( has_post_thumbnail() ){ ?> <?php $thumbID = get_post_thumbnail_id($post->ID); ?> <a href="<?php echo get_post_meta($post->ID, 'URL', true); ?>" title="<?php the_title(); ?>" target="_blank"> <?php the_post_thumbnail(); ?> <span class="view-large"></span> </a> <?php } ?> <?php the_content('<p>Continue Reading →</p>'); ?><br /><br /> <?php if(function_exists('the_ratings')) { the_ratings(); } ?><br /><br /><br /> <?php edit_post_link('Edit this post'); ?> </div> </center> <?php #endwhile; // Reset Post Data wp_reset_postdata(); ?> <?php else : ?> <div id="sort"> <div class="box"> <h2>Sorry, no posts were found</h2> <?php get_search_form(); ?> </div> </div><!-- #sort --> <?php endif; ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Search results : only one result shows up’ is closed to new replies.