Home › Forums › General Issues › Get all field values
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?
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.
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.
I have, but that only gets me the values for the first level of custom fields. The values for deeper nested fields are empty.
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.
You may have to share more on your implementation.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.