[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 18:21:47 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):

 Replying to [comment:9 TimothyBlynJacobs]:
 > Sorry what I mean is that if I pass `visited_states => [ 'NY', 'NJ' ]`.
 I could want two meta rows one for 'NY' and one for 'NJ' or I would want
 one meta key row that saves `[ 'NY', 'NJ' ]`.
 I think I understand now. What if we added some flag? The default flag
 value could false which would keep the current behaviour and true could
 allow you to save the values in separate rows.

 {{{#!php
 <?php
         $new_post = wp_insert_post(
                         array(
                                         'post_title' => 'Test Develop',
                                         'post_name' => 'Test Develop',
                                         'meta_input' => array(
 'array_multiple_rows' => true,
                                                         'key_1' => 1,
                                                         'key_2' => 'some
 string value',
                                                         'key_3' =>
 '15.51',
                                                         'visited_states'
 => array(
 'Massachusetts',
 'Rhode Island',
 'Washington',
                                                         ),
                                         )
                         )
         );
 }}}

 Not sure what a good name for the flag would be, but that would be the
 basic gist of it. If `array_multiple_rows` was true, the code above would
 result in multiple rows of meta rows with the same key, else it would be
 saved as an array.

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


More information about the wp-trac mailing list