Title: Nested loop with &#8216;post__in&#8217;
Last modified: August 19, 2016

---

# Nested loop with ‘post__in’

 *  Resolved [picinae](https://wordpress.org/support/users/picinae/)
 * (@picinae)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/nested-loop-with-post_in/)
 * This is in the single.php. In the loop I trying to acquire posts that I have 
   stated in the post custom value “tema”. It echos fine, but I don’t acquire any
   post. Any suggestion? plz help
 *     ```
       <?php $recept =get_post_custom_values("tema");
         echo $recept[0];
         if (isset($recept[0])):
             $tema=split(',',$recept[0]);
             $my_query = new WP_Query(array('post__in' =>$tema));?>
             <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
             <div class="singel-entry">
             <h2><?php the_title(); ?></h2> <?php edit_post_link('Edit this entry.', '<span>', '</span>'); ?>
             <?php the_content(); ?></div>
             <?php  endwhile;
         else :
                echo "similarpost";
            	similar_posts();
         endif;?>
       ```
   

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

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/nested-loop-with-post_in/#post-1437226)
 * So on that single post you have a custom field called “tema” and for the value
   you have something like **4,56,72** to represent 3 post ID that you want to display?
 * Or do you have multiple values saved for “tema” meaning you have multiple records
   in the wp_postmeta table where the `meta_key` is “tema” and the `meta_value` 
   is one post ID?
 *  Thread Starter [picinae](https://wordpress.org/support/users/picinae/)
 * (@picinae)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/nested-loop-with-post_in/#post-1437294)
 * Yes the first suggestion is right, a custom field called “tema”
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/nested-loop-with-post_in/#post-1437296)
 * Works okay for me in [The Loop](http://codex.wordpress.org/The_Loop) of single.
   php using the WordPress Default theme.
 * Note: to exclude sticky posts had to use:
 *     ```
       $my_query = new WP_Query(array('post__in' =>$tema,'caller_get_posts'=> 1));?>
       ```
   
 * [http://wordpress.pastebin.com/9ZRFPEfC](http://wordpress.pastebin.com/9ZRFPEfC)
 *  Thread Starter [picinae](https://wordpress.org/support/users/picinae/)
 * (@picinae)
 * [16 years, 2 months ago](https://wordpress.org/support/topic/nested-loop-with-post_in/#post-1437302)
 * oh so it works for you. For me, I retrieves no posts. I have really double check
   that the post IDs are correct. It is driving me mad …
 * This works though
    `$test= “cat=41,23&meta_key=tema&meta_value=”. $recept[0];
   echo $test; $my_query = new WP_Query($test); ?>`
 * By the way thanx !!!

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

The topic ‘Nested loop with ‘post__in’’ is closed to new replies.

## Tags

 * [nested loop](https://wordpress.org/support/topic-tag/nested-loop/)
 * [post__in](https://wordpress.org/support/topic-tag/post__in/)
 * [single.php](https://wordpress.org/support/topic-tag/single-php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [picinae](https://wordpress.org/support/users/picinae/)
 * Last activity: [16 years, 2 months ago](https://wordpress.org/support/topic/nested-loop-with-post_in/#post-1437302)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
