Support

Account

Home Forums General Issues Get_fields() returns false until I update the post Reply To: Get_fields() returns false until I update the post

  • @hube2 This is what i was going to do…but are you saying don’t use acf_maybe_get_field()? With my broken data, it seems to work well. I can get the field_key by passing it the name of the field and the post id. I was going to do something simple like this.

    function helper_get_field_key($field_name, $post_id){
      $maybe_field_obj = acf_maybe_get_field( $field_name, $post_id, false );
    
      return $maybe_field_obj['key'];      
    }
    $get_field_key_email = helper_get_field_key('email', $post_id);
    print_r($get_field_key_email);

    Returns: field_5f401336ed966

    This output the field key for the email field that is in that post id.

    If there is a better way to get the field_key programmatically when no value exists yet, I’m all ears…Would love to have a function to use just to get the field key.