Title: query_posts within the loop?
Last modified: August 19, 2016

---

# query_posts within the loop?

 *  [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/query_posts-within-the-loop/)
 * Hi there. For long and complicated reasons I am needing to use query_posts within
   the wordpress loop. Is this possible? if so how?
 *     ```
       <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
       -the content etc-
   
       <?php query_posts('showposts=99&cat=1153'); ?>
       <?php while (have_posts()) : the_post(); ?>	
   
       <li><?php the_title(); ?></li>
   
       <?php endwhile; ?>
   
       <?php endwhile; else: ?>
       <?php endif; ?>
       ```
   
 * I understand the code I place here might be ridiculous…
 * The reason is: I’m making a discography. I want a single post to have a list 
   of posts within a certain category. The category name will be placed there using
   custom fields.

Viewing 1 replies (of 1 total)

 *  Thread Starter [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * (@zefdesign)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/query_posts-within-the-loop/#post-1163068)
 * Okay I did some more searching and have found the perfect code:
 *     ```
       <?php $my_query = new WP_Query('category_name=<strong>HERE-IS-WHERE-I-WANT-TO-INSERT-CUSTOM-FIELD</strong>&orderby=title&order=asc&showposts=100');while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate=$post->ID;?>
   
       <li><?php the_title();?></li>
        <?php endwhile; ?>
       ```
   
 * How could I insert a custom field within that php code???
    I tried this:
 *     ```
       <?php
       $post_title = get_post_meta($post->ID, 'post_title', $single = true);
       ?>
       ```
   
 * then inserting $post_title.
 * Didn’t work.

Viewing 1 replies (of 1 total)

The topic ‘query_posts within the loop?’ is closed to new replies.

## Tags

 * [endwhile](https://wordpress.org/support/topic-tag/endwhile/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [zefdesign](https://wordpress.org/support/users/zefdesign/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/query_posts-within-the-loop/#post-1163068)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
