Support

Account

Home Forums Bug Reports "True / False" field only accept 1 or 0 in database

Solved

"True / False" field only accept 1 or 0 in database

  • There is a problem with the “true / false” field. In the admin edit page field always show true(checked) even my database store “false”. But if database store “1” or “0” the field works like a charm.

    I’m use headless WordPress import csv file with the code, but WordPress convert “1/0” into “True/False”, I’m use custom code to fix input data.

    
    function my_acf_update_value($value, $post_id, $field)
    {
        $value = filter_var($value, FILTER_VALIDATE_BOOLEAN) ? 1 : 0;
        return $value;
    }
    
    add_filter('acf/update_value/name=my_field', 'my_acf_update_value', 10, 3);
    

    In admin edit page use field interface everything is fine.

    Maybe it’s a bug ?

    environment
    WordPress 5.2.2
    Advanced Custom Fields 5.8.3

    Thank you in advance for your cooperation.

  • It’s not a bug in ACF. ACF has always stored 1/0 for true false fields. The problem is with what you’re using to import.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.