displaying custom field only if the value of another meta key is "no"

WordPress Event Management, Calendars & Registration Forums Frontend Submissions displaying custom field only if the value of another meta key is "no"

This topic contains 1 reply, has 2 voices, and was last updated by  Stephen Harris 6 years, 9 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #19226

    Hi Stephen,

    Just one more thing, I would like to display the email address from one meta key if the value of another is “yes”

    so I need an if statement with two conditions, can you look at this psudo code and help me get it to work in php?

    <?php   
    if ( get_post_meta( get_the_ID(), 'eo_application_required', true )  && valueof(eo_application_required = 'Yes'))  {
         printf( '
    Application Email: %s
    ',  esc_html( get_post_meta( get_the_ID(), 'eo_application_email', true ) )); 
    } 
    ?>
    

    So basically what I would like to achieve is if the meta key eo_application_required is true and its value is yes then print the email address stored in the meta key eo_application_email.

    Thanks for your help,
    Lukas

    Lukas Feddern
    #19235

    Hi Lukas,

    Try:

    <?php   
    if ( 'Yes' === get_post_meta( get_the_ID(), 'eo_application_required', true ) ) {
         printf( 
              'Application Email: %1$s',
              esc_html( get_post_meta( get_the_ID(), 'eo_application_email', true ) ) 
         ); 
    } 
    ?>
    

    Please note that the check is case sensitive. ‘YES’, ‘yes’ and ‘yEs’ will not pass 😉

    Stephen Harris
Viewing 2 posts - 1 through 2 (of 2 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.