• netsource

    (@netsource)


    Hello, I am trying to find a solution for being able to exclude any posts with a particular tag from the loop. For instance, I am going to be able to apply a tag such as ‘limit-ip’ to a post and in the code I am going to restrict viewing of those posts to only a select group of ip addresses. Ultimately, this could be used for any number of reasons, but I just can’t get it to work! I cannot find much documentation on ‘tag__not_in’ setting, but it would seem to do what if I want if only I could get it to work. Here is my code on the home page:

    <?php $my_query = new WP_Query(array('tag__not_in'=>array('limitip'),'category_name'=>'features','showposts'=>1));
    while ($my_query->have_posts()) : $my_query->the_post();
    	$do_not_duplicate = $post->ID;?>
    	<div id="post-<?php the_ID(); ?>">
    		<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    		<div><?php the_content('Read the rest of this entry &raquo;'); ?></div>
    	</div>
    <?php endwhile; ?>

    Am I just going about this the wrong way or is there a simpler way to achieve this result? Thanks in advance for any help you can give!

Viewing 2 replies - 1 through 2 (of 2 total)
  • titisite

    (@titisite)

    Hello,

    I think the error comes from “‘tag__not_in’=>array(‘limitip’)”. You have to put the id of the tag and not its name. Try “‘tag__not_in’=>array(X)” where X is the id of the tag ‘limitip’.

    What table is this from? I’m trying to do this as well, and using the id of the tag from wp_terms seems to kill a lot more posts than the ones using that tag.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Excluding a tag from the loop’ is closed to new replies.