Support

Account

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