Support

Account

Home Forums Bug Reports user field doesn't return value

Helping

user field doesn't return value

  • Hi, I’m using ACF PRO and I really like this plugin, it’s very useful for a lot of purpose. I’ve probably found a little bug:
    I was trying to add a single checkbox in the user profile to unsubscribe that user from the mailing list. I’ve created a new field group and initialized the “true/false” field to “checked” (true) as default value but all the emails weren’t sent.
    I tried to get the values of the checkbox with get_field(“my-field”, “user_x”) using the “user_x” to iterate all the users but nothing was returned.
    After few attempts I looked at the database and noticed that “my-field” value wasn’t initialized for any user in the usermeta table. In order to initialize the default value I’ve updated all the user’s profile from wordpress back-end and now everything is working fine.
    Is there another way to inizialize the value? Am I doing something wrong or did I forgot to do something?

    Best regards, Marcello

  • Hi @bortolo

    ACF will only save the data to the database when you save the object (in this case the users). When you set the default value on the field group editor, it won’t automatically change all of the old data you have as it can cause a performance issue.

    Instead, you need to save the old object or set the default value in your code like this:

    $subscribe = get_field('my-field', 'user_99');
    
    if( !$subscribe ){
        $subscribe == true
    }

    I hope this makes sense πŸ™‚

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

You must be logged in to reply to this topic.