Title: Post Loop &amp; query_posts()
Last modified: August 20, 2016

---

# Post Loop & query_posts()

 *  [gward1](https://wordpress.org/support/users/gward1/)
 * (@gward1)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/post-loop-query_posts/)
 * Hello,
 * In single.php I’m attempting to list random posts in the current category.
 * Here’s the code:
 *     ```
       if (have_posts()) : while (have_posts()) : the_post(); ?>
       <!--The Post Is Here-->
       <?php endwhile;
       	$similar_posts = single_cat_title("", false);
       	query_posts( $similar_posts . '&order=ASC&posts_per_page=10' ); ?>
       	<h3>Similar Song Lyrics By This Artist:</h3>
       	<?php
       	while ( have_posts() ) : the_post();
       	echo '<li>'; ?>
       	<a href="<?php the_permalink() ?>" rel="bookmark" title="Song lyrics for <?php the_title(); ?>"><?php the_title(); ?></a>
       	<?php echo '</li>';
       	endwhile; ?><br />
       	<?php else: ?>
       ```
   
 * For some stupid reason it’s not listing the posts from the current posts category.
   Thanks!

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

 *  Thread Starter [gward1](https://wordpress.org/support/users/gward1/)
 * (@gward1)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/post-loop-query_posts/#post-2163970)
 * To clarify it’s pulling the first 10 posts in the database from all categories.
 *  Thread Starter [gward1](https://wordpress.org/support/users/gward1/)
 * (@gward1)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/post-loop-query_posts/#post-2164027)
 * ?
 *  Thread Starter [gward1](https://wordpress.org/support/users/gward1/)
 * (@gward1)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/post-loop-query_posts/#post-2164037)
 * Found this: [http://wordpress.org/support/topic/how-to-get-cat-id-in-query_posts-in-singlephp?replies=10](http://wordpress.org/support/topic/how-to-get-cat-id-in-query_posts-in-singlephp?replies=10)
   which did exactly what I needed.

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

The topic ‘Post Loop & query_posts()’ is closed to new replies.

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

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
