[wp-trac] [WordPress Trac] #10803: get_post_meta doesn't return an array when requested if nothing with that key exists.
WordPress Trac
wp-trac at lists.automattic.com
Tue Sep 29 10:09:51 UTC 2009
#10803: get_post_meta doesn't return an array when requested if nothing with that
key exists.
--------------------------+-------------------------------------------------
Reporter: westi | Owner: westi
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: 2.9
Component: General | Version: 2.8.4
Severity: normal | Resolution:
Keywords: |
--------------------------+-------------------------------------------------
Comment(by azaozz):
Having a default value is a 'convenience' for APIs that store and retrieve
something. It usually saves one conditional. Instead of doing:
{{{
$my_meta = get_post_meta($post_id, 'my_field', true);
if ( empty($my_meta) )
$my_meta = 'default-data';
}}}
we can do:
{{{
$my_meta = get_post_meta($post_id, 'my_field', true, 'default-data');
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/10803#comment:11>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list