[wp-trac] [WordPress Trac] #20752: get_post_meta() accepts int as string value only

WordPress Trac wp-trac at lists.automattic.com
Sat May 26 06:21:14 UTC 2012


#20752: get_post_meta() accepts int as string value only
--------------------------+----------------------
 Reporter:  marcella1981  |       Owner:
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  General       |     Version:  3.4
 Severity:  normal        |  Resolution:  invalid
 Keywords:                |
--------------------------+----------------------
Changes (by duck_):

 * status:  new => closed
 * resolution:   => invalid
 * milestone:  Awaiting Review =>


Comment:

 Replying to [ticket:20752 marcella1981]:
 > {{{
 > for($i = 1; $i <= 3; $i++) :
 >     $field[] = get_post_meta(get_the_ID(), 'custom_field_'.$i);
 > endforeach;
 > }}}

 This has a syntax error. You're starting a for loop but trying to end it
 as a foreach loop. That last line should be `endfor;`.

 You're also starting the for loop at 1 and ending with i equal to 3. This
 means that it's attempting to grab custom_field_1 to custom_field_3
 instead of 0 to 2. You want `for ($i = 0; $i <= 2; $i++) ...`

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


More information about the wp-trac mailing list