Title: Search Function and Query Posts Conflict
Last modified: August 19, 2016

---

# Search Function and Query Posts Conflict

 *  [rapture](https://wordpress.org/support/users/rapture/)
 * (@rapture)
 * [17 years, 10 months ago](https://wordpress.org/support/topic/search-function-and-query-posts-conflict/)
 * Hello everyone,
 * Heres the issue at hand.
 * ive got a search function at the beginning of the page and later down ive got
   a query function that basically pulls out the latests posts from a specific category.
   However when i do a search, it displays all the results in that category for 
   no reason.
 * But when i remove the query function, the search function works perfectly.
 * The search code is the default that usually comes with wordpress and the custom
   display specific category code is as follows:
 *     ```
       <?php query_posts('cat=3&showposts=5'); ?>
   
       <ul>
       <?php while (have_posts()) : the_post(); ?>
       <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
       <?php endwhile;?>
       </ul>
       ```
   
 * It seems as if that code needs to be closed somewhere.
 * Could someone help me figure this out.
 * Thanks

Viewing 1 replies (of 1 total)

 *  [johnny-b](https://wordpress.org/support/users/johnny-b/)
 * (@johnny-b)
 * [17 years, 8 months ago](https://wordpress.org/support/topic/search-function-and-query-posts-conflict/#post-795029)
 * I too would like to know this. Does query_posts() contaminate the search function?
 * My sidebar.php is heavily modified (query_posts is called twice) and the default
   WP search function doesn’t work as expected. I have done a number of test searches
   in which I copy text directly from the content of a published post…and it is 
   no where to be found in the search results. It also seems to have more luck finding
   matches from a year ago than anything recent. Anyway…any thoughts on these issues?

Viewing 1 replies (of 1 total)

The topic ‘Search Function and Query Posts Conflict’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [search function](https://wordpress.org/support/topic-tag/search-function/)

 * 1 reply
 * 2 participants
 * Last reply from: [johnny-b](https://wordpress.org/support/users/johnny-b/)
 * Last activity: [17 years, 8 months ago](https://wordpress.org/support/topic/search-function-and-query-posts-conflict/#post-795029)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
