mardi 1 mai 2018

If statement for WordPress custom field (ACF) shortcode does not work

I have created some WordPress custom fields using ACF.

And I am displaying one of those custom fields inside a page builder (Theme X) using a shortcode I made:

function shortccode_14_eyes() {
    if ( get_field( 'privacy_fourteen_eyes_country' ) ):
        return '<span style="color:#EE121E;"><i class="fa fa-exclamation-triangle"></i></span>';
    endif;
    }
    add_shortcode( '14_eyes', 'shortccode_14_eyes' );

If the field privacy_fourteen_eyes_country is true, it displays a font awesome icon.

The problem is that the icon is displaying no matter what value the field has (true or false).

I thought maybe my code was wrong so I tested it using https://wordpress.org/plugins/custom-content-shortcode/ which generates shortcodes for ACF.

[if field=privacy_fourteen_eyes_country value=1]<span style="color: #ee121e;"><i class="fa fa-exclamation-triangle"></i></span>[/if]

But it has the exact same problem. The icon shows no matter what value the field has.

I'm having a really frustrating and wasteful day trying to get this working.

Can you see what is going wrong?

Here are the settings page for my ACF field: http://nimb.ws/RFKukJ

Aucun commentaire:

Enregistrer un commentaire