Skip to content

Instantly share code, notes, and snippets.

@owise1
Created May 26, 2015 23:01
Show Gist options
  • Save owise1/3950608a75aad9a5591d to your computer and use it in GitHub Desktop.
Save owise1/3950608a75aad9a5591d to your computer and use it in GitHub Desktop.
wordpress functions
<?php
/**
* Useful Wordpress Functions
*/
function first_img($id) {
$files = get_children('post_parent='.$id.'&post_type=attachment&post_mime_type=image');
if($files) :
$keys = array_reverse(array_keys($files));
$j=0;
$num = $keys[$j];
$image=wp_get_attachment_image($num, 'large', false);
$imagepieces = explode('"', $image);
$imagepath = $imagepieces[1];
$thumb=wp_get_attachment_thumb_url($num);
return $thumb;
endif;
}
function acf_img($field, $size){
$ret = get_field($field);
return $ret ? $ret['sizes'][$size] : false;
}
function wp_img($postID, $size){
$ret = wp_get_attachment_image_src($postID, $size);
return $ret[0];
}
function map_method($array, $methodName) {
if(!$array) array();
$returnCode = 'return $a->'. $methodName.';';
return(array_map(create_function('$a', $returnCode), $array));
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment