• In the code below $idspost [] = $post->ID; stores an array of post ID’s belonging to posts related to the current post by tag. How can I display those posts, only if they exist? I need to pass on the array $idspost [] = $post->ID; to something like a standard loop:

    <?php if (have_posts()) : ?>
      <div><p>some header text and styling</p> <!--if no posts nothing will be shown-->
        <?php while (have_posts()) : the_post(); ?>
          do stuff... <!--get the permalink, title etc...-->
        <?php endwhile; ?>
      </div>
    <?php endif; ?>

    My code:

    <?php
    $tags = wp_get_post_tags($post->ID);
    if ($tags) {
      $second_tag = $tags[1]->term_id;
      $args=array(
        'tag__in' => array($second_tag),
        'post__not_in' => array($post->ID),
        'showposts'=>5, //Display this number of related posts
        'ignore_sticky_posts'=>1
       );
      $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      while ($my_query->have_posts()) : $my_query->the_post();
      if (!in_array($post->ID, $ids)) {; $idspost [] = $post->ID; ?>
    
    <?php }
        $ids[]= $post->ID;
        endwhile;
      }
    }
    ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Show array of post ID's’ is closed to new replies.