Weird issue where a tag was not found using the tags search query. That tag is in the CMS (in news entries) as well as the DB, and even shows up in other queries. Query in question:

    set tag = craft.tags({
        search: { query: slug }

All but this tag can't be found for some odd ghostly reason.


You don't need to use the search parameter in this case. I'd avoid using it where ever possible.

{% set tag = craft.tags.slug(slug).first() %}
| improve this answer | |
  • I tried that as well with no luck. It's odd because this isn't a search query. Not really sure what was happening behind the scenes, but thanks for posting this. – biko Apr 13 '16 at 6:14
  • Also I'm not sure whether tags.slug() works. slug() works with entries though. craftcms.com/docs/templating/craft.tags – biko Apr 13 '16 at 6:17
  • It's missing in the documentation, but it should work (it's there in the db table and I'd also used it with success). So yes, odd indeed. Do you have a field with handle "query", because that's what query:slug does, see the table of searching syntaxes. – carlcs Apr 13 '16 at 6:31
  • Also, what's the error you're seeing with this approach? Because I just noticed you didn't use first in your question to get just one tag, so it returns an array. – carlcs Apr 13 '16 at 6:34
  • My apologies. Your query does work! I was using the first() method somewhere further down the code because I was testing the length of the array first. Your query didn't work before because first() was being executed twice. Thanks @carlcs! – biko Apr 16 '16 at 23:39

Turns out that Craft's search indexes were corrupted. After rebuilding the search indexes, that damn tag was correctly showing up.

Hope this helps anyone that might have had just content gone mysteriously MIA.

| 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.