Hi support team,
Thanks for great plugin, first!
I wonder that if there is a way to
retrieve all fields filtered by all location rules which is set.
(a result of should be varied by post_type, user, etc…)
I need this kinda list to remove old & unnecessary fields’ postmeta values from database.
I know get_fields().
What I am imaging is something like get_fields_location_filtered($post_type, $user).
Any idea or clue will be appreciated.
Thanks in advance!
No, there is nothing built into ACF that will do this. Getting every field value for every field sorted by where they are located would be a time consuming task that under most conditions would time out.
Let’s say we wanted to get all the values for all the posts and ignore for a minute users, terms and options. Here is the sequence of things you’d need to do.
And the above will not tell you the fields that are no longer used. It will only give you a list of the fields that are active in a field group.
ACF does not know where fields are located unless it has a “$post_id” value to work with. This value is either assumed to be the current post ID that is being viewed or you must supply it when calling a function.
Hi @John Huebner,
Thank you for your attentive reply!
> ACF does not know where fields are located unless it has a “$post_id” value to work with.
Then I still wonder why ACF can generate a form in ‘post-new’ screen depending on conditions of post_type, user, etc.
Maybe I should dive into ACF core and fetch the code which does the work.
There are internal function in ACF, for example there is a function that gets the field groups based on $post_id, I forget the name of it right now and don’t want to dig, I think it’s
acf_get_field_groups() and you can pass this function an array of arguments if one of them is
'post_id' => $post_id then it will return a list of field groups for that post.
Like I said, ACF requires a post ID to get the field groups or any fields. That post ID could be one of the types that ACF uses for posts, users, terms, etc.
The topic ‘Can I get a field list for a form which is "location rule" applied ?’ is closed to new replies.
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!