|
|
'radio',
'name' => 'fields['.$key.'][library]',
'value' => $field['library'],
'layout' => 'horizontal',
'choices' => array(
'all' => __('All', 'acf'),
'uploadedTo' => __('Uploaded to post', 'acf')
)
));
?>
|
'attachment',
'numberposts' => -1,
'post_status' => null,
'post__in' => $value,
));
$ordered_attachments = array();
foreach( $attachments as $attachment)
{
// create array to hold value data
$ordered_attachments[ $attachment->ID ] = array(
'id' => $attachment->ID,
'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true),
'title' => $attachment->post_title,
'caption' => $attachment->post_excerpt,
'description' => $attachment->post_content,
'mime_type' => $attachment->post_mime_type,
);
}
// override value array with attachments
foreach( $value as $v)
{
if( isset($ordered_attachments[ $v ]) )
{
$new_value[] = $ordered_attachments[ $v ];
}
}
// return value
return $new_value;
}
/*
* format_value_for_api()
*
* This filter is appied to the $value after it is loaded from the db and before it is passed back to the api functions such as the_field
*
* @type filter
* @since 3.6
* @date 23/01/13
*
* @param $value - the value which was loaded from the database
* @param $post_id - the $post_id from which the value was loaded
* @param $field - the field array holding all the field options
*
* @return $value - the modified value
*/
function format_value_for_api( $value, $post_id, $field )
{
$value = $this->format_value( $value, $post_id, $field );
// find all image sizes
$image_sizes = get_intermediate_image_sizes();
if( $value )
{
foreach( $value as $k => $v )
{
if( strpos($v['mime_type'], 'image') !== false )
{
// is image
$src = wp_get_attachment_image_src( $v['id'], 'full' );
$value[ $k ]['url'] = $src[0];
$value[ $k ]['width'] = $src[1];
$value[ $k ]['height'] = $src[2];
// sizes
if( $image_sizes )
{
$value[$k]['sizes'] = array();
foreach( $image_sizes as $image_size )
{
// find src
$src = wp_get_attachment_image_src( $v['id'], $image_size );
// add src
$value[ $k ]['sizes'][ $image_size ] = $src[0];
$value[ $k ]['sizes'][ $image_size . '-width' ] = $src[1];
$value[ $k ]['sizes'][ $image_size . '-height' ] = $src[2];
}
// foreach( $image_sizes as $image_size )
}
// if( $image_sizes )
}
else
{
// is file
$src = wp_get_attachment_url( $v['id'] );
$value[ $k ]['url'] = $src;
}
}
// foreach( $value as $k => $v )
}
// if( $value )
// return value
return $value;
}
}
new acf_field_gallery();
?>