Skip to content

Instantly share code, notes, and snippets.

@purcebr
Created February 19, 2014 21:36
Show Gist options
  • Save purcebr/9102174 to your computer and use it in GitHub Desktop.
Save purcebr/9102174 to your computer and use it in GitHub Desktop.
/**
* A Little Helper for getting specific image sizes from image custom fields.
*/
function get_image_field($field, $size = 'thumbnail')
{
return acf_get_image_thumnails($field, $size, 'field');
}
function get_image_sub_field($field, $size = 'thumbnail')
{
return acf_get_image_thumnails($field, $size, 'sub_field');
}
function get_tax_field_image($field, $tax, $term, $size = 'thumbnail')
{
return acf_get_image_thumnails($field, $size, $tax, $term);
}
function acf_get_image_thumnails($field, $size = 'thumbnail', $type, $term = '')
{
if($type == 'sub_field'):
$image = get_sub_field($field);
elseif($type == 'field'):
$image = get_field($field);
elseif($term != ""):
$image = get_field($field, $type . "_" . $term->term_id);
endif;
if($image) {
$attachment_id = $image['id'];
$image = wp_get_attachment_image_src( $attachment_id, $size );
} else {
return false;
}
return array("url" => $image[0], "width" => $image[1], "height" => $image[2] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment