[wp-trac] [WordPress Trac] #18210: Update_post_meta is case insensitive on meta_key, but get_post_meta is NOT

WordPress Trac noreply at wordpress.org
Fri Mar 8 20:18:44 UTC 2024


#18210: Update_post_meta is case insensitive on meta_key, but get_post_meta is NOT
-------------------------------------------------+-------------------------
 Reporter:  anmari                               |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  closed
 Priority:  normal                               |   Milestone:
Component:  Database                             |     Version:  3.2
 Severity:  normal                               |  Resolution:  worksforme
 Keywords:  dev-feedback needs-patch needs-      |     Focuses:
  unit-tests                                     |  performance
-------------------------------------------------+-------------------------
Changes (by sabernhardt):

 * resolution:  invalid => worksforme


Old description:

> In WordPress 3.3-aortic-dissection and 3.2.1
>
> get_post_meta is case sensitive on the meta-key
>
> BUT
>
> update_post_meta is NOT case sensitive
>
> Thus If there is a pre-existing meta record with a key in say UPPERCASE,
> then one can issue an update for a lowercase key that one can not then
> fetch as it does not exist - only the uppercase key exists.
>

> Example Code
>
> {{{
>
>         $meta = get_post_meta ($post->ID, '_allday');
>         if ($meta ) { echo '<br />got lower: '; var_dump($meta);
>         }
>         $meta = get_post_meta ($post->ID, '_ALLDAY');
>         if ($meta ) { echo '<br />got upper: '; var_dump($meta);
>         }
>         update_post_meta (21, '_allday','Tried to update lowercase');
>         $meta = get_post_meta ($post->ID, '_allday');
>         if ($meta ) { echo '<br />got lower: '; var_dump($meta);
>         }
>         else { echo '<br />Tried to get lower but no go';
>         }
>         $meta = get_post_meta ($post->ID, '_ALLDAY');
>         if ($meta ) { echo '<br />Still have upper: '; var_dump($meta);
>         }
>

> }}}
>

>
> Output of above:
>

>
> got upper: array(1) { [0]=> string(14) "tis the upper." }
> Tried to get lower but no go
> Still have upper: array(1) { [0]=> string(25) "Tried to update lowercase"
> }

New description:

 In WordPress 3.3-aortic-dissection and 3.2.1

 `get_post_meta` is case sensitive on the meta-key

 BUT

 `update_post_meta` is NOT case sensitive

 Thus If there is a pre-existing meta record with a key in say UPPERCASE,
 then one can issue an update for a lowercase key that one can not then
 fetch as it does not exist - only the uppercase key exists.


 Example Code

 {{{

         $meta = get_post_meta ($post->ID, '_allday');
         if ($meta ) { echo '<br />got lower: '; var_dump($meta);
         }
         $meta = get_post_meta ($post->ID, '_ALLDAY');
         if ($meta ) { echo '<br />got upper: '; var_dump($meta);
         }
         update_post_meta (21, '_allday','Tried to update lowercase');
         $meta = get_post_meta ($post->ID, '_allday');
         if ($meta ) { echo '<br />got lower: '; var_dump($meta);
         }
         else { echo '<br />Tried to get lower but no go';
         }
         $meta = get_post_meta ($post->ID, '_ALLDAY');
         if ($meta ) { echo '<br />Still have upper: '; var_dump($meta);
         }


 }}}



 Output of above:



 got upper: `array(1) { [0]=> string(14) "tis the upper." }`
 Tried to get lower but no go
 Still have upper: `array(1) { [0]=> string(25) "Tried to update lowercase"
 }`

--

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/18210#comment:14>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list