I think this should work:
[if each='{TAG}']
Looking at the code that handles this, I see that it can only compare a single term at a time. I’ll see if I can improve it to accept multiple terms, as per your other question.
Thread Starter
flodi
(@flodi)
As always, thank you for your help. But it is not working. It always goes in the [else] branch. The filter in the loop I have before – to get only pages by that tag – works, so I know the tag is passed and captured.
But is seems not working in this [if].
There’s anything I can do to debug that behaviour?
BTW, I’m a PHP coder, so if you need help in offloading some specific coding – i.e. a specific function – just ask! flodi at me dot com
Could you try the following to see what values are being compared?
[pass global=query fields=tag][for each=tag]
Checking if '[each slug]' is equal to '{TAG}'
[/for][/pass]
—
Thank you for the offer to help. The code is quite a jungle in some areas, and I’ve been meaning to refactor it when I have some free time – there’s always more room for improvement. Please feel free to post any suggestions in the forum. There’s a GitHub repo for the plugin too.
Thread Starter
flodi
(@flodi)
Checking if ‘%e4%b8%89%e6%98%8e%e6%b2%bb’ is equal to ‘三明治’三明治’
:-)) I forgot to say I’m building a site in chinese.
Thread Starter
flodi
(@flodi)
Changed in
Checking if '[each]' is equal to '{TAG}'
and I get
Checking if '三明治' is equal to '三明治'
but still, the if it is not executed
I see the problem – [if each] checks the value against [each slug]. Your first example shows that apparently the slug is encoded differently than the value. Hmm, I guess the query variable is getting transformed somewhere along the way..
Ah, I found two undocumented parameters that might help:
[if each_field=name each_value={TAG}]
Mm, no, that is not the best solution. It’s comparing taxonomy name with slug, and for this specific test case they are equal, but often the slug is significantly different from the name, for example: new-category (slug) vs New Category (name).
I’ll have to check how multibyte characters pass through the query variable, to see why the encoding is different on the receiving end. The result of the original test:
Checking if '[each slug]' is equal to '{TAG}'
..should look like this:
if '%e4%b8%89%e6%98%8e%e6%b2%bb' is equal to '%e4%b8%89%e6%98%8e%e6%b2%bb'
…or…
Checking if '三明治' is equal to '三明治'
OK, I made a small update (v3.2.0) with a new parameter to solve this.
[if each={TAG} decode=true]
Thread Starter
flodi
(@flodi)
Wonderful! It works!
You are always the best. Thank you.
I’m glad to hear that worked. I think it was caused by the string going through the query variable, the pass shortcode received a decoded version of the tag. Pretty tricky!