Support

Account

Home Forums General Issues True / False Field Always Returns False

Solving

True / False Field Always Returns False

  • I’m working on a taxonomy archive page called ‘product-type’. This is essentially returning a list of products within a particular category.

    I have a true/false field in ACF and when I try get_field('show_medsafe_id'), it always returns false.

    I’ve read that on an archive page I need to specify the post_id because ACF doesn’t know what post to look for. My code is now:

    $post_id = false;
    $post_id = get_the_ID();
    $custom_field = get_field('show_medsafe_id', $post_id );
    
    if( $custom_field ) {
    	echo 'NZ Medsafe ID: ' . get_field('medsafe_id');
    }

    I’ve also tried this, as per the ACF documentation

    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    
    $custom_field = get_field('show_medsafe_id', $taxonomy . '_' . $term_id);
    
    if( $custom_field ) {
    	echo 'NZ Medsafe ID: ' . get_field('medsafe_id');
    }

    Each time $custom_field’s value is bool(false).

    Can someone point me in the right direction? Let me know if I need to provide more information.

  • jamiemorganward,

    I’m having the same issue.

    get_field('is_cabin','options');

    returns false every time regardless of checked or not.

    It seems to have started at the last update.

  • Having the same issue,

    <?php 
     tvar1 = get_field('tree_votes_display');
      echo '<pre>';
       var_dump( $tvar1 );
      echo '</pre>';
    ?>

    always returns
    bool(false)

    no matter if checkbox is checked or not.

  • Using the last example from the OP, it is almost there. The correct post_id value needs to be given for all get_field() calls when dealing with anything that is not a “post”.

    
    $queried_object = get_queried_object();
    $taxonomy = $queried_object->taxonomy;
    $term_id = $queried_object->term_id;
    $post_id = $taxonomy.'_'.$term_id
    
    $custom_field = get_field('show_medsafe_id', $post_id);
    
    if ($custom_field) {
      echo 'NZ Medsafe ID: '.get_field('medsafe_id', $post_id);
    }
    
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘True / False Field Always Returns False’ is closed to new replies.