• Hi,

    I’m creating a theme which wherein authors each have an allotted space for their posts. I use query_posts to as a filter for the authors, and everything works fine until I use the search, which stopped displaying results. I searched around and saw somewhere that I should be using wp_query instead because query_posts messes up search and pagination, so I did. Now, I sort of have it working. Sort of because I’m still having problems.

    I have the following code:

    <?php $paoloPosts = new WP_Query();
    	$paoloPosts->query('author=1');
    	$search_paoloPosts = $paoloPosts->query('author=1'); 
    
    	if( $paoloPosts->have_posts() ): while($paoloPosts->have_posts()) : $paoloPosts->the_post(); ?>	
    
            <div class="posttitle"><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></div>
    		<div class="postbody"><?php the_excerpt();?></div>
    
    	<?php endwhile; ?>
        <?php else : ?>
        	<div class="postbody">No Search Results Found.</div>
    	<?php endif; ?>

    As I mentioned earlier, the search isn’t working completely. Upon entering a search keyword, search results are displayed and highlighted (I’m using search highlights) BUT along with other posts that have no search results. Also, entering a keyword with no results still causes it to display the posts instead of “No Search Results Found”. I thought it would be as simple as adding another filter to wp_query like so:

    $paoloPosts->query('s=?s&author=1');

    but that doesn’t seem to work. Any ideas on how I can filter out the regular posts that are still displayed despite not having results?

  • The topic ‘wp_query and query_posts break search’ is closed to new replies.