Skip to content

Instantly share code, notes, and snippets.

@korynorthrop
Created March 8, 2017 19:42
Show Gist options
  • Save korynorthrop/a59f756f41d945bcf2330ac37954ff2f to your computer and use it in GitHub Desktop.
Save korynorthrop/a59f756f41d945bcf2330ac37954ff2f to your computer and use it in GitHub Desktop.
ACF Dynamic Field Set
/**
* Dynamically load the Custom CTA image library from RCO Settings allowable images
*/
function acf_load_image_library( $field ) {
// reset CTA selector
$field['choices'] = array();
$images = get_field('cta_image_libary','option'); // get the images from the pre-approved list of images in RCO Settings
if( $images ):
foreach( $images as $image ):
$url = ($image['sizes']['small-rco']) ? $image['sizes']['small-rco'] : $image['sizes']['medium']; // grab small size if it exists
// vars
$label = '<img src="' . esc_url($url) . '">';
$value = $image['ID'];
// append to CTA selector
$field['choices'][ $value ] = $label;
endforeach;
endif;
// return the field
return $field;
}
add_filter('acf/load_field/name=custom_cta_image', 'acf_load_image_library');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment