WordPress.org

Make WordPress Core

Ticket #14017: get_custom_value.14017.diff

File get_custom_value.14017.diff, 1.0 KB (added by filosofo, 4 years ago)
  • wp-includes/post-template.php

     
    654654// 
    655655 
    656656/** 
     657 * Retrieve a single post meta value. 
     658 * 
     659 * @since 3.1.0 
     660 * 
     661 * @uses get_post_meta 
     662 * 
     663 * @param string $field The name of the custom field for which we'll retrieve the value. 
     664 * @param int $post_id Optional.  The ID of the post object with which this custom field is associated.  Defaults to current Loop object or queried object. 
     665 * @return mixed The custom value retrieved. 
     666 */ 
     667function get_custom_value( $field = '', $post_id = 0 ) { 
     668        global $wp_query; 
     669 
     670        $post_id = (int) $post_id; 
     671        if ( empty( $post_id ) ) 
     672                $post_id = (int) get_the_ID(); 
     673 
     674        if ( empty( $post_id ) && is_singular() ) 
     675                $post_id = (int) $wp_query->get_queried_object_id(); 
     676         
     677        return get_post_meta( $post_id, $field, true ); 
     678} 
     679 
     680 
     681/** 
    657682 * Retrieve post custom meta data field. 
    658683 * 
    659684 * @since 1.5.0