• Currently I’m able to pull the latest two posts onto my static front page like this…

    <?php
    $args = array( 'numberposts' => 2, 'order'=> 'DESC', 'orderby' => 'post_date' );
    $postslist = get_posts( $args );
    
    foreach ($postslist as $post) :  setup_postdata($post); ?>
      <p>
        <?php the_time('F j, Y'); ?>
      </p>
      <h5>
        <a href="<?php echo get_permalink(); ?>">
          <?php the_title(); ?>
        </a>
      </h5>
      <div>
        <?php the_excerpt(); ?>
      </div>
    <?php endforeach;
    
    ?>

    That all works well – it displays the date, title link, excerpt and More link for the latest two posts.

    However, I’m looking for a way to prevent any posts that have been tagged with the word ‘exclude’ from displaying in this area. Does anyone know if there is a way to tweak the above code to accommodate that? Or is there a better way of achieving it?

    (I’ve been playing around with tag__not_in but that seems to be something to do with WP_Query and I can’t work out how to incorporate it.)

    Any help would be greatly appreciated.

The topic ‘Latest posts list: Exclude posts with certain tags’ is closed to new replies.