Created
March 3, 2017 22:13
-
-
Save mrbobbybryant/3d82a7aa88fbe5c4f2586a58c6771e94 to your computer and use it in GitHub Desktop.
Get Custom Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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