Created
March 8, 2017 19:42
-
-
Save korynorthrop/a59f756f41d945bcf2330ac37954ff2f to your computer and use it in GitHub Desktop.
ACF Dynamic Field Set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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