Support

Account

Home Forums General Issues get_fields returns empty

Solved

get_fields returns empty

  • Hi,

    I have made an ACF form to insert data into WP. I also have an offline dataset that I wrote a wp-cli script to bulk import as new posts. To fill in the acf fields I insert them using wp-cli post meta add <id> <field> <value>

    Everything seems to be fine. If I go to the wp-admin edit form and open one of the posts all data is there.

    However, I want to make a customized rendering of this data in the blog post page. So I use a function in functions.php based on one of my theme’s filter (tc_post_list_content of Customizr) to manipulate how the post list is rendered.

    Unfortunately, trying to do:

    $fields = get_fields(get_the_ID());

    returns false. How can I overcome this problem?

    I noticed that if I go to the web interface and edit one of the imported post entries, then (even without changing anything), I click the “Update” button and then go to my posts list page and reload, get_fields returns properly the fields for that entry.

    Any help would be very welcome.

  • Hi @sigma

    Please keep in mind that ACF saves two entries in the wp_postmeta table, which are the value and the reference.

    The value looks like this:

    custom_field_name : the value

    While the reference looks like this:

    _custom_field_name : field_12345657890abc

    Where “field_12345657890abc” is the field key.

    Reading your explanation, I believe the issue was because you haven’t added the reference key to the database. Could you please add the reference too and see how it goes 🙂

  • indeed, for those coming here with the same problem, I set with wp-cli custom_field and _custom_field (the second setting it to each field’s ACF key value) via the wp add post meta and it worked like a charm.

    thank you.

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

The topic ‘get_fields returns empty’ is closed to new replies.