Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6991905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:33:55+00:00 2026-05-27T19:33:55+00:00

I want to show 5 posts in the sidebar, EXCLUDING all those post I

  • 0

I want to show 5 posts in the sidebar, EXCLUDING all those post I tagged “hp” (ID=11). Apparentely there are a lot of way to do that with categories, but with tags it is really hard to find.

Here is the code I have.

<?php query_posts( array( 'tag' => -11, 'posts_per_page' => 5, 'orderby' => 'date', 'order' => 'DESC' ) ); ?>
<?php while (have_posts()) : the_post(); ?>
<?php if (class_exists('MultiPostThumbnails')
            && MultiPostThumbnails::has_post_thumbnail('post', '3-image')) :
                MultiPostThumbnails::the_post_thumbnail('post', '3-image'); endif; ?>
<div>in <?php   the_category(', '); ?></div>

<?php   the_title(); ?>
<?php
$count = 0;
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$count++;
if ($count <= 1 ) {
echo '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a> ';
}
}
}
?>
  <?php endwhile;?>

It shows only 5 posts, showing only the first tag, but it keeps the posts with the tag I am trying to exclude.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:33:56+00:00Added an answer on May 27, 2026 at 7:33 pm

    You need to use WP_Query class along with tag__not_in.

    <?php
    $the_query = new WP_Query( array( 'tag__not_in' => array( 11 ) ) );
    
    while ( $the_query->have_posts() ) : $the_query->the_post();
    
         // Whatever you want to do goes here
    
    endwhile;
    
    // Reset Post Data
    wp_reset_postdata();
    ?>
    

    You can get more information about WP_Query class here – http://codex.wordpress.org/Class_Reference/WP_Query

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have while loop and in that there's forum posts.I want to show number
I want to show HTML content inside Flash. Is there some way to do
I have a database table that contains blog posts. I want to show on
On my home page where all my blog posts are I want to show
We want to show a hint for a JList that the user can select
I want to show first element that is hidden by jquery. my html code
I'm working on a blog and want to show my posts in eastern time
I want to show user's post count from specific category. Currently, I can only
I have comment model that references (foreign key) a post model and there is
This is for a category index of blog posts-I only want to show the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.