Created
April 19, 2012 11:09
-
-
Save trovster/2420303 to your computer and use it in GitHub Desktop.
Simple custom get custom field function, which handles when a key doesn't exist.
This file contains hidden or 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 | |
| function template_get_custom_field($custom, $key, $prefix = 'custom_') { | |
| if(!empty($custom[$prefix . $key][0])) { | |
| return $custom[$prefix . $key][0]; | |
| } | |
| return ''; | |
| } | |
| // examples | |
| $custom = get_post_custom($post->ID); | |
| template_get_custom_field($custom, 'name'); // looks for 'custom_name' | |
| template_get_custom_field($custom, 'thumbnail_id', ''); // looks for 'thumbnail_id' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment