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 8123263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:07:27+00:00 2026-06-06T06:07:27+00:00

I am trying to write a query post such that it returns a list

  • 0

I am trying to write a query post such that it returns a list fixed list of posts from a category along with any of the one tag associated with it. For eg:

<?php $arg = array('cat' => '1','showposts' => 10,'offset' => 0); query_posts($arg); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<a class="post-link" title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php $posttags = get_the_tags(); $count=0; if ($posttags) { foreach($posttags as $tag) { $tag_link = get_tag_link($tag->term_id); $count++; if ($count == 1) 
{ echo '<a class="tag-link" href="'.get_tag_link($tag->term_id).'">#'.$tag->name.'</a>'; } } } ?> 

Posts in Topic A

Post_Title_1 #tag1
Post_Title_2 #tag2
Post_Title_3 #tag3
Post_Title_4 #tag2 <– I don’t wan’t this Post one as Tag2 has been displayed already.

The issue is I want only posts with unique tags to be shown…. How can i do that… Please help

  • 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-06-06T06:07:29+00:00Added an answer on June 6, 2026 at 6:07 am
    <?php 
    $existing_tags = array();
    
    $arg = array('cat' => '1','showposts' => 10,'offset' => 0); query_posts($arg);
    
    if (have_posts()) : while (have_posts()) : the_post(); 
    
    //get tag and checking if it existed already
    $posttags = get_the_tags();
    $skip_post = false;
    
    if ($posttags) {
        foreach ($posttags as $tag) {
            $tag_id = $tag->term_id; //the tag's id
            if (isset($existing_tags[$tag_id])) {
                $skip_post = true; //skip this post if the tag already exists
            } else { 
                $existing_tags[$tag_id] = true;
                $skip_post = false; //otherwise track it in our array
            }
            break; //stop after parsing the first tag
        }
    }
    
    if ($skip_post) {
        break; //skip the post
    }
    //display the post and tags as usual
    ?>
    <a class="post-link" title="<?php the_title(); ?>" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    <?php
    echo '<a class="tag-link" href="'.get_tag_link($tag->term_id).'">#'.$tag->name.'</a>';
    ?> 
    

    So basically you need to move the code that gets the tags to the top, check against an array if it already exists. If it does, go to the next post, otherwise display the rest of the post.

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

Sidebar

Related Questions

I'm trying to write a query that will return the closest match from a
I'm trying to write a custom SQL query that will create a list of
I'm trying to write a small Python script that will get query results from
I'm trying to write a query to pull some info from our database and
I am trying to write a query that sorts the results of a table
I am making a page that accepts post data from any number of pages
Im trying to write a query that will find and display all of my
I’m trying to write a python script that sends a query to TweetSentiments.com API.
I'm trying to write an INNER JOIN query. I wanted to get rows/information that
I'm trying to write a page that allows users to type a post and,

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.