Title: query_posts() problem
Last modified: August 19, 2016

---

# query_posts() problem

 *  [drewshen](https://wordpress.org/support/users/drewshen/)
 * (@drewshen)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/)
 * Hello, I created a page template in order to display a certain category in my
   blog.
 *     ```
       <?php query_posts('cat=5'); ?>
       	<?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>
       ```
   
 * The query_posts line is what I added to my page template file, the category’s
   id being 5. However, when I go to the page on my site, it simply displays the
   page title, and no data, just a blank page. Does anyone know what I am doing 
   wrong? Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [thelastknight](https://wordpress.org/support/users/thelastknight/)
 * (@thelastknight)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/#post-1030062)
 * If that is your full loop, then you’re missing some bits.
 * Below is a simple example
 *     ```
       <?php query_posts('cat=5'); ?>
   
       <?php while (have_posts()) : the_post(); ?>
   
       <?php the_content(); ?>
   
       <?php endwhile; ?>
       ```
   
 *  Thread Starter [drewshen](https://wordpress.org/support/users/drewshen/)
 * (@drewshen)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/#post-1030066)
 * Thanks for the reply! That is actually not my full loop, I merely posted those
   two lines to display the line of code I added for the sake of saving space. here
   is the full loop:
 *     ```
       <?php query_posts('cat=5'); ?>
       	<?php if (have_posts()) : while (have_posts()) : the_post(); // the loop ?>
   
       	<!--post title-->
       	<h1 id="post-<?php the_ID(); ?>"><?php the_title(); ?></h1>
   
       	<!--post text with the read more link-->
       	<?php the_content(); ?>
   
       	<!--for paginate posts-->
       	<?php link_pages('<p><strong>Pages:</strong> ', '</p>', 'number'); ?>
   
           <?php //comments_template(); // uncomment this if you want to include comments template ?>
   
       	<?php endwhile; // end of one post ?>
       	<?php else : // do not delete ?>
   
       	<h3>Page Not Found</h3>
           <p>We're sorry, but the page you are looking for isn't here.</p>
           <p>Try searching for the page you are looking for or using the navigation in the header or sidebar</p>
   
           <?php endif; // do not delete ?>
       ```
   
 *  [thelastknight](https://wordpress.org/support/users/thelastknight/)
 * (@thelastknight)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/#post-1030069)
 * Try restructuring the top two lines to –
 *     ```
       <?php
   
        $temp = $wp_query;
   
        $wp_query= null;
   
        $wp_query = new WP_Query();
   
        $wp_query->query('cat=-5');
   
       ?>
   
       <?php if (have_posts()) : ?>
   
       <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
       ```
   
 * Do you have any other loops on the page?
 *  Thread Starter [drewshen](https://wordpress.org/support/users/drewshen/)
 * (@drewshen)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/#post-1030087)
 * Still no dice, this is the only loop i have on the page.
 *  Thread Starter [drewshen](https://wordpress.org/support/users/drewshen/)
 * (@drewshen)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/#post-1030302)
 * [http://www.alliancechristiancenter.org/development/news/events/](http://www.alliancechristiancenter.org/development/news/events/)
 * This is the link to the page I am trying to display the category in. I have tried
   even just displaying all posts on the page, but it seems as if no data is being
   retreived at all
 *  [renato_s](https://wordpress.org/support/users/renato_s/)
 * (@renato_s)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/#post-1030306)
 * Try using get_posts instead, and see if it works. I had a similar problem and
   used get_posts to solve it, but I had other loops on the page…
 * [http://codex.wordpress.org/Template_Tags/get_posts](http://codex.wordpress.org/Template_Tags/get_posts)

Viewing 6 replies - 1 through 6 (of 6 total)

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [renato_s](https://wordpress.org/support/users/renato_s/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/query_posts-problem/#post-1030306)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
