Title: return a single post in a loop
Last modified: August 22, 2016

---

# return a single post in a loop

 *  Resolved [Julian Fox (greataussiepie)](https://wordpress.org/support/users/greataussiepie/)
 * (@greataussiepie)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/return-a-single-post-in-a-loop/)
 * I am trying to create a single-{post_type}.php template file, I don’t know why
   my custom post type template is returning all the posts. Not sure where i’m going
   wrong, can anyone help me out?
 *     ```
       <?php
   
       $args = array ( 'post_type' => 'foxware_recipe' );
   
        $the_query = new WP_Query ( $args );
   
       ?>
   
       <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
   
       	<h3><?php the_title(); ?></h3>
       	<?php the_content(); ?>
       	<hr>
   
       <?php endwhile; else: ?>
   
       	<p>There are no posts or pages</p>
   
       <?php endif; ?>
       ```
   

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

 *  Thread Starter [Julian Fox (greataussiepie)](https://wordpress.org/support/users/greataussiepie/)
 * (@greataussiepie)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/return-a-single-post-in-a-loop/#post-5600000)
 * change this line `<?php
    $args = array( ‘post_type’ => ‘foxware_recipe’ ); … ?
   >`
 * to
 *     ```
       <?php
       $args = array( 'post_type' => array( 'foxware_recipe' ), 'posts_per_page' => '1' );
       ...
       ?>
       ```
   
 * seemed to do the trick. Although not sure if that is the correct standard.
 *  [Josh](https://wordpress.org/support/users/josh401/)
 * (@josh401)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/return-a-single-post-in-a-loop/#post-5600001)
 * Check the codex on [WP_Query](http://codex.wordpress.org/Class_Reference/WP_Query).
 * You’ll want to add a `posts_per_page` limit to your `$args`.
 *     ```
       $args = array('post_type' => 'foxware_recipe', 'posts_per_page' => 1);
       ```
   
 *  Thread Starter [Julian Fox (greataussiepie)](https://wordpress.org/support/users/greataussiepie/)
 * (@greataussiepie)
 * [11 years, 5 months ago](https://wordpress.org/support/topic/return-a-single-post-in-a-loop/#post-5600003)
 * thanks for confirming that 🙂

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

The topic ‘return a single post in a loop’ is closed to new replies.

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [display](https://wordpress.org/support/topic-tag/display/)
 * [single](https://wordpress.org/support/topic-tag/single/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Julian Fox (greataussiepie)](https://wordpress.org/support/users/greataussiepie/)
 * Last activity: [11 years, 5 months ago](https://wordpress.org/support/topic/return-a-single-post-in-a-loop/#post-5600003)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
