ACF, PHP | Type: PHPConditional Based on Field Value

Conditional based on values for single-value fields (radio buttons, select, etc)

For regular WordPress post meta:
<?php
$customfield = get_post_meta($post->ID, 'custom_field', true);
if ( $customfield == 'textstring' ) {
    do stuff
}
?>

For ACF:
<?php
$customfield = get_field('custom_field');
if ( $customfield == 'textstring' ) {
    do stuff
}
?>

for ACF repeater subfield:
<?php
$customfield = get_sub_field('custom_field');
if ( $customfield == 'textstring' ) {
    do stuff
}
?>

We use cookies in order to give you the best possible experience on our website. By continuing to use this site, you agree to our use of cookies.
Accept