Pull all posts with certain tag WordPress

I have this code:

    <div class="col-md-4 col-sm-4 col-xs-12 mob">
  <?php 
  $args = array('tag_slug__and' => array('testtag'));
  $loop = new WP_Query( $args );
  while ($loop->have_posts() ) : $loop->the_post();
  ?>
  <a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
    <?php 
    if(has_post_thumbnail()) {                    
      $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
      echo '<img src="' . $image_src[0]  . '" width="100%"  />';
    } 
    ?>
    <h4><?php the_title(); ?></h4>   

    <?php the_excerpt(); ?>

  <?php endwhile; ?>
  <?php wp_reset_query(); ?>
</a>

Read More

Which gets a post which has the tag ‘testtag’.

Instead of copying this code, and using ‘testtag1’, ‘testtag2’

How can I just grab ALL the posts which have the tag ‘testtag’ and just keep adding them into 4 columns?

Any links/help

Related posts

1 comment

  1. Nevermind, simple fix!!

     <div class="row" style="margin-top:20px;">
    
          <?php 
          $args = array('tag_slug__and' => array('testtag'));
          $loop = new WP_Query( $args );
          while ($loop->have_posts() ) : $loop->the_post();
          ?>
          <div class="col-md-4 col-sm-4 col-xs-12 mob">
          <a style="color:#333; text-decoration:none;" href="<?php echo get_permalink(); ?>">
            <?php 
            if(has_post_thumbnail()) {                    
              $image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),'full' );
              echo '<img src="' . $image_src[0]  . '" width="100%"  />';
            } 
            ?>
            <h4><?php the_title(); ?></h4>   
    
            <?php $trimexcerpt = get_the_excerpt();
    
            $shortexcerpt = wp_trim_words( $trimexcerpt, $num_words = 10, $more = '… <br/> <a href="">Read More ...</a>' ); 
    
            echo '<a style="color:#333; text-decoration:none;" href="' . get_permalink() . '"><p>' . $shortexcerpt . '</p></a>'; 
    
            ?>
      </div>
          <?php endwhile; ?>
          <?php wp_reset_query(); ?>
        </a>
    
    </div>
    

Comments are closed.