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

<p>Hope this helps anyone that might have had just content gone mysteriously MIA.</p>

CC BY-SA 3.0
2016-04-13T00:34:51.220Z
2016-04-13T00:34:51.220Z
biko
<p>You don't need to use the search parameter in this case. I'd avoid using it where ever possible.</p>

<pre><code>{% set tag = craft.tags.slug(slug).first() %}
</code></pre>

CC BY-SA 3.0
2016-04-13T06:14:32.397Z
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
CC BY-SA 3.0
2016-04-13T06:17:14.320Z
Also I'm not sure whether tags.slug() works.  slug() works with entries though.  https://craftcms.com/docs/templating/craft.tags
biko
CC BY-SA 3.0
2016-04-13T06:31:40.333Z
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](https://craftcms.com/docs/searching).
carlcs
CC BY-SA 3.0
2016-04-13T06:34:30.960Z
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
CC BY-SA 3.0
2016-04-16T23:39:33.707Z
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
CC BY-SA 3.0
2016-04-17T06:00:35.093Z
No worries, I'm glad you got it resolved.
carlcs
CC BY-SA 3.0
2016-04-13T01:00:13.427Z
2016-04-13T01:00:13.427Z
carlcs
<p>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:</p>

<pre><code>{%
    set tag = craft.tags({
        search: { query: slug }
    }).limit(1)
%}
</code></pre>

<p>All but this tag can't be found for some odd ghostly reason.</p>

<search><tags><queries>
Tag mysteriously not found
# Tag mysteriously not found

(Asked by: username_0 on 2016-04-13)

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 }
    }).limit(1)
%}

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

**Tags:** search, tags, queries

---

## 2 answers

### Answer by username_0 on 2016-04-13. Score: 2 | Accepted answer

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.


---

### Answer by username_1 on 2016-04-13. Score: 3

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() %}

> **Comments:**
> **username_0**: 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.  
> **username_0**: Also I'm not sure whether tags.slug() works.  slug() works with entries though.  https://craftcms.com/docs/templating/craft.tags  
> **username_1**: 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](https://craftcms.com/docs/searching).  
> **username_1**: 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.  
> **username_0**: 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!  
> **username_1**: No worries, I'm glad you got it resolved.  

---

