Support

Account

Home Forums General Issues get_field( '{field}', 'option' ) return null for non-admin users

Solved

get_field( '{field}', 'option' ) return null for non-admin users

  • With the update to 5.11 getting option values via get_field( '{field}', 'option' ) returns null for non-admin users. For admin users everything works as expected.

    Is this intended behavior or a bug? How coud this worked around?

    Context

    Option page is created via

    
        acf_add_options_sub_page(array(
            'page_title' 	=> 'Title',
            'menu_title'	=> 'Title',
            'parent_slug'	=> 'options-general.php',
        ));
    

    Field is created via acf_add_local_field_group() in acf/init.

  • When is your field group created?

    See this topic: https://support.advancedcustomfields.com/forums/topic/get_field-returning-null-after-update/

    On what hook are are you running your function that adds the local field group?

  • @hube2 As mentioned in my first post my field group is created via acf_add_local_field_group() using the acf/init hook.

    Anything else I can provide to help investigating this?

  • Sorry, I missed that part.

    Not really. I tested getting and displaying an options page value on a site when not logged into the site and it’s working as expected, so my test did not rely on the user type.

    Is there anything in the code for adding the field group or fields that’s dependent on the user type or if the user is logged in or if the page is and admin page? Conditionally creating fields could cause this depending on the condition.

  • @hube2 That was it! The plugin in question had an unnecessary capability check that caused it fail to register the field.

    Thanks for the prompt support

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

You must be logged in to reply to this topic.