Support

Account

Home Forums General Issues get_fields( $post_id ) returns empty array

Solved

get_fields( $post_id ) returns empty array

  • I’m working with AFC in a plugin I’m writing.

    I want to use get_fields( $post_id ) to get all the fields for my post. For some reason, it just returns an empty array:

    array(1) { [""]=> bool(false) }

    On the other hand, get_field( 'field_name', $post_id ) works just fine.

    Any ideas why?

    Update

    I am calling the function in a the_content filter which, so I’ve read, might be called before the plugin is fully loaded. Does this make sense?

    This is the order in which the actions are loaded :

    add_action( 'after_setup_theme', array( $this , 'register_post_types' ) );
    add_action( 'after_setup_theme', array( $this , 'acf_setup' ) ); // Meta boxes are created in this action with 'register_field_group' function
    add_filter( 'the_content', array( $this , 'my_content_filter' ) );
  • I’ve solved the issue myself. I had changed the field keys so they were the same as the field name which was causing a conflict. I’ve changed them back to the standard field_cefffd0f7209b format.

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

You must be logged in to reply to this topic.