WordPress.org

Support

Support » Themes and Templates » [Resolved] Skip Posts in Loop if has_tag

[Resolved] Skip Posts in Loop if has_tag

  • I’m doing a query where I want to show 2 posts from a custom post type in my sidebar, but I’m also grabbing a variable from the URL string which equals the tag the post should be in, and then skip any posts in the loop that don’t have that tag.

    Can anyone tell me what the code would be for [if (!has_tag(‘MYTAG’)) skip this post]

    Here’s my current code:

    <?php $bannerzip = $_GET["sk"]; ?>
    <?php $querystr = "SELECT * FROM (SELECT wposts.* FROM $wpdb->posts wposts WHERE wposts.post_status = 'publish' and wposts.post_type = 'cn_ad' ORDER BY rand()) as y limit 50 ";
    $pageposts = $wpdb->get_results($querystr, OBJECT);
    if ($pageposts): foreach ($pageposts as $post):
    <?php if(has_tag($bannerzip) ) { ?><?php if ( has_post_thumbnail() ) { ?><?php the_post_thumbnail(); ?><?php } ?><?php } ?>
    <?php endforeach; endif; ?>

    Essentially, I’m just looking for the code that says “skip this post if it doesn’t have a certain tag.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] Skip Posts in Loop if has_tag’ is closed to new replies.
Skip to toolbar