Home › Forums › ACF PRO › Get next field value in foreach loop through field group › Reply To: Get next field value in foreach loop through field group
Hi John,
This helps in terms of understanding why acf_get_fields();
returns null values however this doesn’t solve the more pressing issue of getting the value of the next item in the $fields array.
Using var_dump($values);
gives you all the fields from that page which is not really what I want here. I really want only the fields in the selected group. And this $values array doesn’t include the group that the fields are associated with.
Thus, when in the foreach ($fields as $field) loop, it *does* retrieve the values however the only way to retrieve the NEXT item (which is really what I need) requires having the values in the initial array.
Since there’s no there there, it won’t work.
Maybe I could take a look at the acf_get_fields();
function and craft another one that retrieves the values as well.
My ultimate goal is to add a show/no show toggle for each field. The client wants to be able to save the values with each post so it is visible in the admin but toggle the visibility on the front end.
There are lots of fields and field groups for each post (these are from a “Properties” CPT) and there are 83 fields associated with each property in 7 groups. Not all of the fields will have toggles so that is why I was grabbing them by group.
If there’s another way to go about this, I’m all ears. I thought about adding a special character as a flag (something like adding “%” at the beginning of the data) but this will only work for text or text area fields. We have radio buttons, checkboxes, drop downs as well.
Any ideas?
Thanks!
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!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.