WordPress.org

Ready to get started?Download WordPress

Forums

Exclude tag from WP_Query (2 posts)

  1. canutedechou
    Member
    Posted 3 years ago #

    im doing a query for show the last post form a category
    and i have:
    <?php $recent = new WP_Query("cat=5&showposts=1"); while($recent->have_posts()) : $recent->the_post();?>

    but i want to exclude the tag "featured" from there
    i try with tag=-featured and tag=-8 (wich is the ID) and its not working
    any idea?

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    http://codex.wordpress.org/Function_Reference/WP_Query#Tag_Parameters

    tag__not_in

    try for instance:

    $recent = new WP_Query(array('cat' => 5, 'posts_per_page' => 1, 'tag__not_in' => array(8)));

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.