Home › Forums › ACF PRO › Dynamically add options › Reply To: Dynamically add options
It doesn’t matter in which level of the repeaters the field is placed.
Try this code to get the image sizes as options for your radio field:
<?php
function acf_load_image_sizes_field_choices( $field ) {
global $_wp_additional_image_sizes;
$field['choices'] = array();
foreach ( get_intermediate_image_sizes() as $size ) {
if ( in_array( $size, array('thumbnail', 'medium', 'medium_large', 'large') ) ) {
$width = get_option( "{$size}_size_w" );
$height = get_option( "{$size}_size_h" );
$crop = (bool) get_option( "{$size}_crop" );
} elseif ( isset( $_wp_additional_image_sizes[ $size ] ) ) {
$width = $_wp_additional_image_sizes[ $size ]['width'];
$height = $_wp_additional_image_sizes[ $size ]['height'];
$crop = $_wp_additional_image_sizes[ $size ]['crop'];
}
$image_crop = "";
if ( $crop == 1 ) {
$image_crop = " - cropped";
}
// set the value for field values and labels as you like
$value = $size;
$label = $size . " ({$width}x{$height}{$image_crop})";
$field['choices'][ $value ] = $label;
}
// add full size option
$field['choices'][ 'full' ] = "Full size";
return $field;
}
add_filter('acf/load_field/name=image_size', 'acf_load_image_sizes_field_choices');
?>
This filter works for the field named image-size
.
I hope you get the idea how this works and you can adjust it to your needs.
Regards
Thomas
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.