Home Forums General Issues get_field() and get_fields() returns: array(field_key => false)


get_field() and get_fields() returns: array(field_key => false)

  • Straight to the point:

    Here’s what i get when i run get_post_meta():

    // Removed unrelated meta fields such as "_edit_last"
    array(6) {
      array(1) {
        string(30) " removed..."
      array(1) {
        string(19) "field_51ee1db3aa7a0"
      array(1) {
        string(18) " removed..."
      array(1) {
        string(19) "field_51ee1f63241e5"

    Here’s what i get when i run get_fields():

    array(2) {

    What i want it to return (and what it *should* return according to the doc):

    // Pseudocode, ofc
      'field_name' => 'field value'

    I have compared the field keys through admin and they are indeed correct.

    I found this in the documentation for get_fields():

    This is a very simple function which finds ALL custom field values **(that don’t start with an “_”)**…

    But i have both with and without _ stored. I assume that’s normal, but i don’t understand why it returns the wrong data. It works just fine everywhere else, it’s just for this specific field group it messes up.

    Any ideas?

  • Hi @[email protected]

    Perhaps you need to pass through the $post_id parameter to the get_fields function.

    Looks like totaly different data is being returned. This may be due to ACF loading from the wrong post_id

  • Hi, @elliot

    I was passing the $post_id to both functions, i even tried manually passing it.

    I solved it though! The problem was that i was calling the functions before ACF has initiated completely (i’m guessing). I put the code inside the init action and now it runs beautifully.

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

The topic ‘get_field() and get_fields() returns: array(field_key => false)’ is closed to new replies.