Title: query_posts question
Last modified: August 19, 2016

---

# query_posts question

 *  Resolved [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/query_posts-question-2/)
 * On my site, I have three sections at the bottom, where I am using query_posts
   to pull in partial content of three Pages. After this section, I have a conditional
   set to show something if it’s only the index page – however, the conditional 
   isn’t working.
 * It seems the reason is because of the three queries that appear prior. Is there
   something I’m missing?
 *     ```
       <?php query_posts('page_id=8');
             if (have_posts()) : ?>
                 <div>
                 <?php while (have_posts()) : the_post(); ?>
                 <?php echo get_post_meta($post->ID, 'meta', TRUE); endwhile; ?>
                 </div>
                 <?php endif; ?>
   
       <?php query_posts('page_id=9');
       if (have_posts()) :
       ?>
                 <div>
                 <?php while (have_posts()) : the_post(); ?>
                 <?php echo get_post_meta($post->ID, 'meta', TRUE); endwhile; ?>
                 </div>
                 <?php endif; ?>
   
       <?php query_posts('page_id=10');
       if (have_posts()) :
       ?>
                 <div>
                 <?php while (have_posts()) : the_post(); ?>
                 <?php echo get_post_meta($post->ID, 'meta', TRUE); endwhile; ?>
                 </div>
                 <?php endif; ?>
   
       <?php if(is_home()) { get_sidebar(); }
             get_footer(); ?>
       ```
   
 * Would anyone know why the conditional doesn’t work? If I remove the queries, 
   or place the conditional *before* the queries, then it works just fine. But I
   need it to come after, and the conditional refuses to work as long as the queries
   are there (I’ve even tried placing the conditional in the sidebar – or in the
   footer – but it still doesn’t acknowledge it because of the queries).
 * Am I missing something? Any help would be appreciated.

Viewing 1 replies (of 1 total)

 *  Thread Starter [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * (@doodlebee)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/query_posts-question-2/#post-703204)
 * Got it. I just replaced the “query_posts” with a variable. I.e. :
 *     ```
       <?php query_posts('page_id=10');
       if (have_posts()) :
       ?>
                 <div>
                 <?php while (have_posts()) : the_post(); ?>
                 <?php echo get_post_meta($post->ID, 'meta', TRUE); endwhile; ?>
                 </div>
                 <?php endif; ?>
       ```
   
 * became:
 *     ```
       <?php $page_ten = new WP_query('page_id=10');
       if (have_posts()) :
       ?>
                 <div>
                 <?php while ($page_ten->have_posts()) : $page_ten->the_post(); ?>
                 <?php echo get_post_meta($post->ID, 'meta', TRUE); endwhile; ?>
                 </div>
                 <?php endif; ?>
       ```
   
 * Now the conditional works.

Viewing 1 replies (of 1 total)

The topic ‘query_posts question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [Doodlebee](https://wordpress.org/support/users/doodlebee/)
 * Last activity: [18 years, 2 months ago](https://wordpress.org/support/topic/query_posts-question-2/#post-703204)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
