• Resolved picinae

    (@picinae)


    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)
  • 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

    (@picinae)

    Yes the first suggestion is right, a custom field called “tema”

    Works okay for me in 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));?>

    https://wordpress.pastebin.com/9ZRFPEfC

    Thread Starter picinae

    (@picinae)

    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.