Title: Removing query_posts()
Last modified: August 21, 2016

---

# Removing query_posts()

 *  [patrick_here](https://wordpress.org/support/users/patrick_here/)
 * (@patrick_here)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/removing-query_posts/)
 * I’m trying to remove **query_posts()** following the advice [here on the WordPress Codex](http://codex.wordpress.org/Pagination#Removing_query_posts_from_the_main_loop)
   but it’s not working for me. If I try the advice in those instructions, the first
   page of my blog returns only one post instead of the five that I specify.
 *  If I only add the “pre_get_posts” to my functions.php,it works …however it is
   still using get_posts() …which is inefficient. I think the reason is that there
   is a previous call to get_posts in my index.php which I’m not replacing. That
   call is simply getting a list of categories. See code below …with the first and
   second calls to query_posts() shown in bold. I’m primarily trying to replace 
   the second one:
 *     ```
       <div id="middle" class="clearfloat">
       	<img src="<?php echo get_option('home'); ?>/wp-content/themes/arthemia/images/category.png" class="clearfloat" alt="" />
       	<?php $display_categories = array(5,6,7,8,11); $i = 1;
       	foreach ($display_categories as $category) { ?>
   
       	<div id="cat-<?php echo $i; ?>" class="category">
       		<?php <strong>query_posts("showposts=1&cat=$category")</strong>?>
       		<span class="cat_title"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></span>
       		<a href="<?php echo get_category_link($category);?>"><?php echo category_description($category); ?></a>
       	</div>
   
       	<?php $i++; ?>
           	<?php } ?>
   
       	</div>
   
       	<?php } ?>
   
       	<div id="bottom" class="clearfloat">
   
       	<div id="front-list">	
   
       	<?php
             $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
             <strong>query_posts("cat=-27,-28&paged=$page&posts_per_page=5");</strong> ?>
   
       	<?php while (have_posts()) : the_post(); ?>
       ```
   
 * How can I make this work?

Viewing 1 replies (of 1 total)

 *  Thread Starter [patrick_here](https://wordpress.org/support/users/patrick_here/)
 * (@patrick_here)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/removing-query_posts/#post-4521357)
 * Okay, I’ve managed to eliminate that first call to query_posts() but my index.
   php still has a prior call to** query_posts()** that I can’t remove because it
   uses a custom taxonomy that I defined and I’m passing the custom taxonomy as 
   an argument to query_posts(). It looks like this:
 *     ```
       <?php $args = array('homepageposts' => 'Featured'); query_posts($args); ?>
       <?php while (have_posts()) : the_post(); ?>
       ```
   
 *  I think I need to get rid of **all** of the calls to query_posts() because prior
   calls to query_posts() will mess up the subsequent sections where I’m trying 
   to eliminate them. Any advice as to what to do about this call to query_posts()
   of a specific taxonomy?

Viewing 1 replies (of 1 total)

The topic ‘Removing query_posts()’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [patrick_here](https://wordpress.org/support/users/patrick_here/)
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/removing-query_posts/#post-4521357)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
