Title: Query_posts does not go
Last modified: August 19, 2016

---

# Query_posts does not go

 *  Resolved [elistr](https://wordpress.org/support/users/elistr/)
 * (@elistr)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/)
 * Hello,
 * I have problem with Query_posts ( [http://codex.wordpress.org/Template_Tags/query_posts](http://codex.wordpress.org/Template_Tags/query_posts)).
   At my widget ( [http://czechbracelet.info](http://czechbracelet.info) ) there
   is title “Promo” and under it i have:
 * `<?php query_posts('category_name=Promo'); ?>`
 * but nothing shows me! 🙁
 * Can you help me?
 * Thank you for reply!

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670883)
 * I put similar code in a [Loop](http://codex.wordpress.org/The_Loop) in a [Page Template](http://codex.wordpress.org/Pages)
   and it worked just fine.
 *  Thread Starter [elistr](https://wordpress.org/support/users/elistr/)
 * (@elistr)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670910)
 * Thank MichaelH for reply!
 * Can you post here your part of code (where loop is)?
 * This does not go 🙁
 *     ```
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
   
       <?php query_posts('category_name=Promo'); ?>
   
        <?php endwhile; else: ?>
        <p>Sorry, no posts matched your criteria.</p>
        <?php endif; ?>
       ```
   
 * Thank you for reply!
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670913)
 * The query_posts() call should go BEFORE the if (have_posts()) piece. Like so:
 *     ```
       <?php query_posts('category_name=Promo'); ?>
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       ...
       <?php endwhile; else: ?>
       Sorry, no posts matched your criteria.
       <?php endif; ?>
       ```
   
 * query_posts always needs to be before the Loop.
 *  Thread Starter [elistr](https://wordpress.org/support/users/elistr/)
 * (@elistr)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670914)
 * thank you for reply, but I am starting to be lame duck.
    I add this code to sidebar–
   where Promo is ([http://czechbracelet.info](http://czechbracelet.info))
 *     ```
       <?php query_posts('category_name=Promo'); ?>
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
       <?php endwhile; else: ?>
       Sorry, no posts matched your criteria.
       <?php endif; ?>
       ```
   
 * But the result of this code is Sorry, no posts matched your criteria. 🙁
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670921)
 * Try this:
 *     ```
       <?php
       $myposts = query_posts('category_name=Uncategorized');
       if ($myposts):
       foreach ($myposts as $post):
       setup_postdata($post);
       the_title();
       endforeach;
       else :
       // Nothing Found
       endif;
       ?>
       ```
   
 *  Thread Starter [elistr](https://wordpress.org/support/users/elistr/)
 * (@elistr)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670928)
 * Thank you for this code, but it shows anything different.
 * I have changed “Uncategorized” to Promo ([http://czechbracelet.info/?cat=48](http://czechbracelet.info/?cat=48))
   it should show 2 links to 2 articles (Mike Jones v Praze už 20. ledna (Roxy),
   BBARÁK # 68 + Indy & Wich – Kids On The Click Tour 2007 DVD)
 * But it shows this paragraph (without any links):
 * Ke smrti legendárního Pimp C-ho se vyjádřili Bun-B a Mike JonesKe smrti legendárního
   Pimp C-ho se vyjádřili Bun-B a Mike Jones
 * You can check this at [http://czechbracelet.info/](http://czechbracelet.info/)(
   the second sidebar – left, centre).
 * Any ideas?
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670938)
 * Yes, I just displayed `the_title();` as an example. You will want to look at 
   [The Loop](http://codex.wordpress.org/The_Loop) for possibilities to display 
   such as `<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2
   >`
 *  Thread Starter [elistr](https://wordpress.org/support/users/elistr/)
 * (@elistr)
 * [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670941)
 * Yesssssssss! Thank you so much! Viva la MichaelH and WordPress 🙂

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

The topic ‘Query_posts does not go’ is closed to new replies.

## Tags

 * [category_name](https://wordpress.org/support/topic-tag/category_name/)
 * [query_posts](https://wordpress.org/support/topic-tag/query_posts/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [elistr](https://wordpress.org/support/users/elistr/)
 * Last activity: [18 years, 3 months ago](https://wordpress.org/support/topic/query_posts-does-not-go/#post-670941)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
