• Resolved sonmar

    (@soniamariano)


    Hi,

    I’m trying for hours to figure this out without success… I have a CPT named faculty and inside I have an ACF field named faculty_linkedin.

    In a specific page of my site, and for simplicity sake, I have three independent dropdown select boxes for my client to choose from the list of faculty (program_faculty1, program_faculty2 and program_faculty3). These select boxes store the post ID.

    I am able to retrieve each ACF faculty_linkedin using PASS

    [pass field=program_faculty1]
    [content type=faculty id={FIELD} field=faculty_linkedin]
    [/pass]

    But now I need to check if the ACF field faculty_linkedin is empty or not and echo more information accordingly.

    [pass field=program_faculty1]
    [if id={FIELD} type=faculty field=faculty_linkedin]
    THE FIELD IS NOT EMPTY 
    [content type=faculty id={FIELD} field=faculty_linkedin]
    [else]
    THE FIELD IS EMPTY
    [/if]
    [/pass]

    This is always giving me “THE FIELD IS EMPTY”, even when the field has input.

    I also tried adding empty=true and empty=false inside the IF statement, but nothing changed.

    Can someone point me into the right direction here?

    Many thanks in advance!

    • This topic was modified 4 years, 2 months ago by sonmar.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Try

    [pass field=program_faculty1]
    [if field={FIELD} value=""]
    NOW ITS EMPTY
    [else]
    NOW NOT EMPTY
    [/if]
    [/pass]
    • This reply was modified 4 years, 2 months ago by polarracing.
    Thread Starter sonmar

    (@soniamariano)

    Thank you @polarracing , however I need to check if the field faculty_linkedin, from a post with the ID given by the field program_faculty1, is empty or not.

    I would use a variable.

    [pass field=program_faculty1]
    [set my_var][content type=faculty id={FIELD} field=faculty_linkedin][/set]
    [/pass]
    [if var=my_var]
     NOW YOU HAVE A VALUE IN YOUR FIELD
    [else]
     NOW YOUR FIELD IS EMPTY
    [/if]
    Thread Starter sonmar

    (@soniamariano)

    Thank you for your time @polarracing . It didn’t work either.

    I tried with nested PASS and somehow got it working…

    [pass field=program_faculty1]
    [-pass id={FIELD} type=faculty field=faculty_linkedin]
    [if {-FIELD}]
    EMPTY
    [else]
    NOT EMPTY
    [/if]
    [/-pass]
    [/pass]

    However, this doesn’t make sense to me, because I thought the IF statement was by default TRUE (ie, saying that there is content inside that field) and in here, it’s working the other way.

    Whats the content of my_var after setting the variable when you use my example.

    And have you tried
    [if var=my_var value=""]

    • This reply was modified 4 years, 2 months ago by polarracing.
    Thread Starter sonmar

    (@soniamariano)

    Hmm, I must have done something wrong the first time, because now your suggestion is now working.

    Either way, I changed the IF statement and added an empty=”false” and it is working in a way that makes sense to me and allows me to use {FIELD} in more places:

    Here’s my final code:

    [pass field=program_faculty1]
      [-pass id={FIELD} type=faculty field=faculty_linkedin]
    [if pass='{-FIELD}' empty="false"]
    <a href="{-FIELD}" target="_blank">
    <i aria-hidden="true" class="fab fa-linkedin" style="font-size: 2em;"></i>
    </a>
    [/if]
    [/-pass]
    [/pass]      
    

    What do you think? I couldn’t find any info about how to use variables, so I’m thinking of going this way instead ??

    I guess you could use empty=false as well with variables.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘IF with PASS and checking for empty field’ is closed to new replies.