Home › Forums › Feature Requests › Speed up work with new option in gallery field › Reply To: Speed up work with new option in gallery field
add_filter('acf/load_value/name=gallery_field_name', 'bob4bob_load_gallery_from_post', 10, 3);
function bob4bob_load_gallery_from_post($value, $post_id, $field) {
if (!value !== NULL) {
// field has a value, don't change it
return $value;
}
$images = get_attached_media('image', $post_id);
if (count($images)) {
$value = array();
foreach ($images as $image) {
$value[] = $image->ID;
}
}
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.