Home Forums Bug Reports get_field empty with admin_init hook


get_field empty with admin_init hook

  • I have a work around with get_post_meta() but the 5.11 update broke a behavior that isn’t explained in the page here:

    I’ve simplified the code below to only include the important parts. The $termsDate value is empty with 5.11.1

    add_action('admin_init', 'redirect_terms');
    function redirect_terms()
    	if( is_admin() && current_user_can('edit_posts') && !current_user_can('upload_files'))
    		$post = myGetPostFunction(get_current_user_id());
    		$termsDate = get_field('expert_latest_terms_date', $post->ID);
  • If your following what you linked to there should be no issue with using get_field() on the admin init hook because this happens after acf is initialized. Whatever your issue is it is not in the code you’ve provided.

    It could be in the function called here

    $post = myGetPostFunction(get_current_user_id());

    or it could possibly be in how the field is defined.

  • Hey @pstonge

    Are you also registering the fields on admin_init? If so, you might need to set a priority hook for the get_field to be later than the registration.

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

You must be logged in to reply to this topic.