Can somebody help me with the basic construction a Query module query to pull some info out of the Favorites and Tag modules from Solspace? I've tried the following using standard tags but this information isn't available that way, at least as far as I can tell.

"Here's what I'm looking to do: Create a list of tags belonging to the entries a user has in their Favorites collections.

Put differently, a user saves 100 entries (using the Favorites module) and each of those entries has multiple tags. I'd like to list all the tags for all the favorited entries in a user's favorites collections.

I've tried various queries but my sql skills are at a novice level and this seems to be an advanced query I don't know how to do. Can anyone please help me? Thanks


This is a common question and similar responses have been provided in other threads, which are good reads to get some inspiration:

We have also (recently) added a page in our Solspace Solutions section on the subject: http://support.solspace.com/solution/articles/4000047779-create-a-list-of-all-unique-tags-from-a-entries-list

A summary here, with modifications for Favorites:

To get a list of tags from specific entries in one list, and without tags being repeated (i.e. display a list of unique tags), {exp:tag:cloud} can't be used because there is no entry_id="" parameter.

Because {exp:tag:tags} is repeated at each {exp:channel:entries} (or {exp:favorites:entries}) loop, chances are you get duplicates of some tags. You'll need to create an array of unique tags to filter out duplicates. One way to do this is with PHP.

Enable PHP in your Templates and set it to Output. Then create your array:

{!-- Start with an empty array --}
<?php $tags = array(); ?>

{exp:favorites:entries /* your parameters */}
   {exp:tag:tags entry_id="{entry_id}"}
      {!-- add the tag to the array. Duplicate tag_ids will be filtered this way --}
      <?php tags['{tag_id}'] = '{tag_name}'; ?>

Now your $tags array should have unique keys (the tag_id), and therefore tag_names should be unique as well. Finally, simply loop through the unique list of tags outside of and after {exp:favorites:entries}. Below we're building a comma-separated list first, then trimming the final comma. Finally, we output the final string:

{!-- Start with an empty string --}
<?php $tag_list = ''; ?>    

<?php foreach($tags as $tag) :?>
   {!-- Concatenate tags --}
   <?php $tag_list .= $tag . ", "; ?>
<?php endforeach ?> 

{!-- Trim the final extra comma and display to screen --}
<?php echo rtrim($tag_list, ", "); ?>

There are likely other ways to do this, using Stash perhaps, but this uses native tools in EE.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.