[wp-trac] [WordPress Trac] #10882: Add default data to get_*_meta()

WordPress Trac wp-trac at lists.automattic.com
Fri Oct 2 05:35:51 UTC 2009


#10882: Add default data to get_*_meta()
-------------------------------+--------------------------------------------
 Reporter:  Denis-de-Bernardy  |       Owner:     
     Type:  enhancement        |      Status:  new
 Priority:  normal             |   Milestone:  2.9
Component:  General            |     Version:  2.9
 Severity:  normal             |    Keywords:     
-------------------------------+--------------------------------------------

Comment(by scribu):

 Firstly, just because you can set empty custom fields, doesn't mean you
 should. When you no longer need a custom field, just delete it. Therefore,
 returning an empty string or array is ok.

 Secondly, like westi said, most of the time you don't have a default
 value.

 If you really need that, just write a wrapper function:

 {{{
 function get_post_meta_with_default($id, $key, $value, $single, $default)
 {
   $data = get_post_meta($id, $key, $value, $single);

   if ( empty($data) )
     return $default;

   return $data;
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/10882#comment:7>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list