• Resolved flodi

    (@flodi)


    I’m trying to do that:

    [pass global=query fields=tag][for each=tag][if '{TERM}'='{TAG}']<div class="onetag tagselected">[else]<div class="onetag">[/if]<a href="?tag=[each slug]">[each name]</a></div>[/for][/pass]

    i.e. using a different class if the tag in the for loop is the same in the URL get request. But it is not working.

    What I’m doing wrong?

    https://www.ads-software.com/plugins/custom-content-shortcode/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Eliot Akira

    (@miyarakira)

    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

    Plugin Author Eliot Akira

    (@miyarakira)

    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

    Plugin Author Eliot Akira

    (@miyarakira)

    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}]
    Plugin Author Eliot Akira

    (@miyarakira)

    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 '三明治'
    Plugin Author Eliot Akira

    (@miyarakira)

    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.

    Plugin Author Eliot Akira

    (@miyarakira)

    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!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘if inside for inside pass not working’ is closed to new replies.