[wp-trac] [WordPress Trac] #41949: Allow multiple values for the same meta key to be passed to `wp_insert_post()`

WordPress Trac noreply at wordpress.org
Fri Jun 26 20:04:09 UTC 2020


#41949: Allow multiple values for the same meta key to be passed to
`wp_insert_post()`
-------------------------------+------------------------------
 Reporter:  desrosj            |       Owner:  (none)
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  4.4
 Severity:  normal             |  Resolution:
 Keywords:  has-patch          |     Focuses:
-------------------------------+------------------------------

Comment (by stuffradio):

 Here's the newest result for where I am at now.


 {{{
 mysql> SELECT * FROM wp_postmeta WHERE post_id=40 OR post_id=41;
 +---------+---------+----------------+-------------------------------------------------------------------------------+
 | meta_id | post_id | meta_key       | meta_value
 |
 +---------+---------+----------------+-------------------------------------------------------------------------------+
 |     153 |      40 | key_1          | 1
 |
 |     154 |      40 | key_2          | some string value
 |
 |     155 |      40 | key_3          | 15.51
 |
 |     156 |      40 | visited_states |
 a:3:{i:0;s:13:"Massachusetts";i:1;s:12:"Rhode
 Island";i:2;s:10:"Washington";} |
 |     157 |      41 | key_1          | 1
 |
 |     158 |      41 | key_2          | some string value
 |
 |     159 |      41 | key_3          | 15.51
 |
 |     160 |      41 | visited_states | Massachusetts
 |
 |     161 |      41 | visited_states | Rhode Island
 |
 |     162 |      41 | visited_states | Washington
 |
 +---------+---------+----------------+-------------------------------------------------------------------------------+
 10 rows in set (0.00 sec)
 }}}


 {{{#!php
 <?php
 wp_insert_post(
                         array(
                                         'post_title' => 'Single Meta
 Post',
                                         'post_name' => 'single-meta-post',
                                         'meta_single' => true,
                                         'meta_input' => array(
                                                         'key_1' => 1,
                                                         'key_2' => 'some
 string value',
                                                         'key_3' =>
 '15.51',
                                                         'visited_states'
 => array(
 'Massachusetts',
 'Rhode Island',
 'Washington',
                                                         ),
                                         )
                         )
         );
 }}}

 {{{#!php
 <?php
 wp_insert_post(
                         array(
                                         'post_title' => 'Multiple meta
 rows',
                                         'post_name' => 'multiple-rows',
                                         'meta_single' => false,
                                         'meta_input' => array(
                                                         'key_1' => 1,
                                                         'key_2' => 'some
 string value',
                                                         'key_3' =>
 '15.51',
                                                         'visited_states'
 => array(
 'Massachusetts',
 'Rhode Island',
 'Washington',
                                                         ),
                                         )
                         )
         );
 }}}

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


More information about the wp-trac mailing list