Support

Account

Home Forums General Issues Get all field values

Solving

Get all field values

  • Hi guys,

    I have used ACF extensively in a site, with multiple nested fields in flexible contents and repeaters.
    Now I need to populate a search index with my data. So what I want is a list of all field values in a given post, however deeply they’re nested, and I want to filter for text values (only field types ‘text’, ‘textarea’ and ‘wysiwyg’). Also, I’d like to do it generically without knowing the field names and group names.

    How would I do that?
    I’ve tried get_fields() which gives me everything except the values for sub fields.
    Then I’ve tried get_field_object() in a loop for each field, but again no values for sub fields.
    Then I’ve tried a direct $wpdb search in the post_meta table, but the field ID doesn’t seem to match the meta_id column in post_meta.

    How do I get every field value filtered by type?

    Thanks!

  • Have you tried using the get_field_objects()?

    if you create a page with just the following code for the output, you can see array values for all the fields:

    $fields = get_field_objects($post_id);
    
    echo '<pre>';
    	print_r($fields);
    echo '</pre>';

    You should be able to get the information you need from there.

  • Hi @uwe

    Thanks for reaching out to us.

    Unfortunately, there is currently no method to load all the sub_field values from a page using the plugins API.

    You would to implement some custom to check if the item is a repeater field.

    I’ll mark this as a feature request for the developer to take a look at when he has time.

  • @bosoxbill
    I have, but that only gets me the values for the first level of custom fields. The values for deeper nested fields are empty.


    @James

    Great, thank you!

  • Hey guys, any update on this? I’m really in need of this feature that used to work on v4 with get_field_object(key) but is now linked to a specific post.

  • Hi @kevinch ,

    I would recommend that you open a new ticket for your issue.

    On the same, the get_field_object should work just fine with the field_key as documented herein.

    https://www.advancedcustomfields.com/resources/get_field_object/

    You may have to share more on your implementation.

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

The topic ‘Get all field values’ is closed to new replies.