Home Forums Front-end Issues If statement for True/False field


If statement for True/False field

  • I have created a True/False ACF field called ‘custom_acf’ and im trying to do an if statement where if its true it shows something, and if false shows something else. Below is what i have, but it is displaying as false whether the the true/false is ticked or not. Where am i going wrong?

    $advantagePremium = false;

    if ( get_field(‘custom_acf’)) {
    $advantagePremium == true;
    } else {
    $advantagePremium == false;

    if ($advantagePremium == true) {
    return “Link 1“;
    } elseif ($advantagePremium == false) {
    return “Link 2“;

  • Hi @will-lawrencefuturform-co-uk

    Could you please make sure that the get_field() function returns the correct value? Could you please debug it like this:

    var_dump( get_field('custom_acf') );

    If that doesn’t return the correct data, it’s possible that the get_field() function is loaded outside of The Loop. In this case, could you please pass the post ID to the get_field() function like this:

    get_field('custom_acf', 99)

    Where ’99’ is the post ID.

    If still no joy, could you please share the JSON or XML export file of your field group so I can check your setup?

    Thanks 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.