Skip to content

Instantly share code, notes, and snippets.

@jpcontrerasv
Created August 26, 2016 04:46
Show Gist options
  • Save jpcontrerasv/5a494568b0d3276d370648a77eae773a to your computer and use it in GitHub Desktop.
Save jpcontrerasv/5a494568b0d3276d370648a77eae773a to your computer and use it in GitHub Desktop.
ACF If Else field
<?php if ( get_field( 'field_name' ) ): ?>
This is displayed when the field_name is TRUE or has a value.
<?php else: // field_name returned false ?>
This is displayed when the field is FALSE, NULL or the field does not exist.
<?php endif; // end of if field_name logic ?>
@RNX-art
Copy link

RNX-art commented Oct 22, 2020

what if i want to show and remove based on user role? (front end)

answer please
Thanks

@HowardCrane
Copy link

HowardCrane commented Aug 25, 2021

what if i want to show and remove based on user role? (front end)

answer please
Thanks

You probably don't need help anymore, but for anyone else looking:
What you need to do is make another separate PHP condition or make an && (and) condition, depending on what you need.

Example:
<?php if( get_field('has_prequel') || current_user_can('editor') ): ?> Success <?php endif;?>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment