Support » Plugin: Custom Content Shortcode » Test if Variable = XYZ

  • We’ve got a variable inside a repeater that is defined with one of several ACF fields depending on some other stuff. We need to test if that variable is equal to a specific ACF field (not its value, just the field name) but can’t seem to get the right shortcode figured out.

    We’ve tried this…

    [pass vars]
    [if {FIELDTOFETCH}=featured_image]
    <td>SHOW-IMAGE</td>
    [else]
    <td>[field {FIELDTOFETCH}]</td>
    [/if]
    [/pass]

    And tried this, too:

    [pass vars]
    [if pass='{FIELDTOFETCH}' value=featured_image]
    <td>SHOW-IMAGE</td>
    [else]
    <td>[field {FIELDTOFETCH}]</td>
    [/if]
    [/pass]

    No joy.

    Thanks,
    MT

    • This topic was modified 1 year, 8 months ago by mpturner.
    • This topic was modified 1 year, 8 months ago by mpturner.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Use variables. For the field whatever

    [set yourvariable]WHATEVER[/set]
    [set fieldname][field whatever out=field-label][/set]
    [pass vars]
      [if var=fieldname value='{YOURVARIABLE}']
        <td>SHOW-IMAGE</td>
      [else]
        <td>DO WHAT YOU WANT</td>
      [/if]
    [/pass]
    • This reply was modified 1 year, 8 months ago by polarracing.
    Thread Starter mpturner

    (@mpturner)

    Thanks… still trying to get things to work (this all resides inside a nested repeater so it gets a little confusing).

    Second question… our PASS is nested. What inside of this needs to have a leading dash (-)? The -FIELDTOFETCH variable works as intended with the dash as it is shown if that matters.

    [-pass vars]
    [if var=fieldtofetch value=featured_image]
    <td>[link field=image-url][field image featured_image width=24px][/link]</td>
    [else]
    <td>[field {-FIELDTOFETCH}]</td>
    [/if]
    [/-pass]

    Its a bit confusing. It depends where the variable is defined.
    If its defined before the first [pass vars] the it works without – if defined within a [pass vars] then you need a nested [-pass vars]and to call the variable -{VARIABLE}

    • This reply was modified 1 year, 7 months ago by polarracing.
    • This reply was modified 1 year, 7 months ago by polarracing.
    Thread Starter mpturner

    (@mpturner)

    Got it, thanks. Just wanted to verify none of the IF statements needed dashes. Still trying to get the image to load when the variable = the ACF slug/id, “featured_image.” Probably have more questions at some point 🙂

    Thanks for the help!

    For repeating functionality you can also use Meta Shortcodes.

    Those are helpfull if you need to call a function all over the place. I for example use it to calculate the age of people.

    I pass a birth-date to the Meta Shortcode and get back the age of the person.

    Thread Starter mpturner

    (@mpturner)

    Excellent, thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Test if Variable = XYZ’ is closed to new replies.