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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:31:02+00:00 2026-06-18T12:31:02+00:00

$tagged = Os :: model()-> withTags(windows, windows7, windowsXp)-> find(); I want to retrieve the

  • 0
$tagged = Os :: model()-> withTags("windows, windows7, windowsXp")-> find();

I want to retrieve the records that are tagged with any of the following
windows, windows7, windowsXp.

By default the tags are generating a condition which are AND-ed. I want to use the OR operator for the tags. So if the record contains windows, windows7 but not windowsXp it won’t be retrieved.

I’ve managed to find a workaround, by editing the getFindByTagsCriteria() in the ETaggableBehavior.php that comes in the extension folder.

/**
     * Get criteria to limit query by tags.
     * @access private
     * @param array $tags
     * @return CDbCriteria
     */
    protected function getFindByTagsCriteria($tags) {
            $criteria = new CDbCriteria();

            $pk = $this->getOwner()->tableSchema->primaryKey;

            if(!empty($tags)){
                    $conn = $this->getConnection();
                    $criteria->select = 't.*';

                    if(count($tags) >0){
                            $criteria -> join .= "
                                    JOIN {$this->getTagBindingTableName()} bt 
                                    ON t.{$pk} = bt.{$this->getModelTableFkName()}

                                    JOIN {$this->tagTable} tag0 
                                    ON tag0.{$this->tagTablePk} = bt.{$this->tagBindingTableTagId} AND (";


                            for($i = 0, $count = count($tags); $i < $count; $i++){
                                    $tag = $conn->quoteValue($tags[$i]);
                                    $criteria->join .= " tag0.`{$this->tagTableName}` = $tag OR";
                            }
                            $criteria -> join = rtrim($criteria -> join, "OR");
                            $criteria -> join .= ")";
                    }
            }

            if($this->getScopeCriteria()){
                    $criteria->mergeWith($this->getScopeCriteria());
            }

            return $criteria;
    }

I would really appreciate any other way without having to modify the plugin itself.

  • 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-18T12:31:03+00:00Added an answer on June 18, 2026 at 12:31 pm

    Sam from Yii development team helped me solve this by adding two more functions to the ETaggableBehavior.php

    /**
     * Get criteria to limit query to match any of tags specified
     * @access private
     * @param array $tags
     * @return CDbCriteria
     */
    protected function getFindByAnyTagsCriteria($tags) {
        $criteria = new CDbCriteria();
    
        $pk = $this->getOwner()->tableSchema->primaryKey;
    
        if(!empty($tags)){
            $conn = $this->getConnection();
            foreach($tags as &$tag) {
                $tag = $conn->quoteValue($tag);
            }
            unset($tag);
            $tags = implode(', ', $tags);
    
            $criteria->select = 't.*';
            $criteria->join .=
                "JOIN {$this->getTagBindingTableName()} bt ON t.{$pk} = bt.{$this->getModelTableFkName()}
                JOIN {$this->tagTable} tag ON tag.{$this->tagTablePk} = bt.{$this->tagBindingTableTagId} AND tag.`{$this->tagTableName}` IN ($tags)";
            }
        }
    
        if($this->getScopeCriteria()){
            $criteria->mergeWith($this->getScopeCriteria());
        }
    
        return $criteria;
    }
    
    /**
     * Limit current AR query to have any of tags specified.
     * @param string|array $tags
     * @return CActiveRecord
     */
    public function taggedWithAnyOf($tags) {
        $tags = $this->toTagsArray($tags);
    
        if(!empty($tags)){
            $criteria = $this->getFindByAnyTagsCriteria($tags);
            $this->getOwner()->getDbCriteria()->mergeWith($criteria);
        }
    
        return $this->getOwner();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

before I start I want to point out that I tagged this question as
Let's suppose I have a Discussion model, and that a discussion can be tagged.
I have the following model, where different texts are tagged to different collections of
I have a Photo model with the following method to search for associated tags
This post is incorrectly tagged 'send' since I cannot create new tags. I have
I have a list of puzzles that are tagged with specific Themes. Think questions
I am trying to build an ANTLR grammar that parses tagged sentences such as:
What I'm looking for is a QuerySet containing any objects not tagged. The solution
I'm trying to find a more or less foolproof way to solve the following
For example, I have a named scope sfw_only in my Image model that returns

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.