Home › Forums › Add-ons › Gallery Field › Problem with use acf/format_value/ filter for gallery field › Reply To: Problem with use acf/format_value/ filter for gallery field
Hope this helps you
// add filter w/high priority so it runs after ACF
add_filter('acf/format_value/name=gallery', 'add_values_to_gallery', 20, 3);
function add_values_to_gallery($value, $post_id, $field) {
if (!$value || !is_array($value) || !count($value)) {
// no value, bail early
return $value;
}
// loop through gallery
// note & before $images => pass by reference
// so that changes to $image effect original
// http://php.net/manual/en/language.references.pass.php
foreach ($value as $index => &$image) {
// add a value to this image
$image['my-new-index'] = 'my new value';
}
return $value;
}
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.