Skip to content

Instantly share code, notes, and snippets.

@mrbobbybryant
Created March 3, 2017 22:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrbobbybryant/3d82a7aa88fbe5c4f2586a58c6771e94 to your computer and use it in GitHub Desktop.
Save mrbobbybryant/3d82a7aa88fbe5c4f2586a58c6771e94 to your computer and use it in GitHub Desktop.
Get Custom Image
<?php
/**
* This function will return all the image data (id, url)
* @param $post_id int The post id.
* @param $name string the name of your custom field you used when creating the field.
*
* @return mixed
*/
function get_custom_upload( $post_id, $name ) {
$key = sprintf( '%s-hidden-field', $name );
return get_post_meta( $post_id, $key, true );
}
/**
* This function will all return the image url.
* @param $post_id int The post id.
* @param $name string the name of your custom field you used when creating the field.
*
* @return mixed
*/
function get_custom_upload_url($post_id, $name) {
$image_data = get_custom_upload( $post_id, $name );
if ( ! empty( $image_data ) ) {
return $image_data['src'];
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment