Title: using  a custom query in the loop
Last modified: August 18, 2016

---

# using a custom query in the loop

 *  [Marcomail](https://wordpress.org/support/users/marcomail/)
 * (@marcomail)
 * [18 years, 9 months ago](https://wordpress.org/support/topic/using-a-custom-query-in-the-loop/)
 * I’d use a custom query to retrieve some specific article in the loop.
 * The custom query is like this
 *     ```
       <?php $posts = $wpdb->get_results
       foreach ($posts as $post) :
       setup_postdata($post);
       ```
   
 * the loop is the usual
 * `<?php if (have_posts()) : while (have_posts()) : the_post(); ?>`

The topic ‘using a custom query in the loop’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [Marcomail](https://wordpress.org/support/users/marcomail/)
 * Last activity: [18 years, 9 months ago](https://wordpress.org/support/topic/using-a-custom-query-in-the-loop/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
