[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 17:58:26 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: needs-patch | Focuses:
-------------------------------+------------------------------
Comment (by stuffradio):
@desrosj
{{{
mysql> SELECT * FROM wp_postmeta WHERE post_id=12;
+---------+---------+----------------+-------------------+
| meta_id | post_id | meta_key | meta_value |
+---------+---------+----------------+-------------------+
| 15 | 12 | key_1 | 1 |
| 16 | 12 | key_2 | some string value |
| 17 | 12 | key_3 | 15.51 |
| 18 | 12 | visited_states | Massachusetts |
| 19 | 12 | visited_states | Rhode Island |
| 20 | 12 | visited_states | Washington |
+---------+---------+----------------+-------------------+
6 rows in set (0.00 sec)
}}}
I have created a modification locally to wp_insert_post. If I understand
correctly, this was the result you were wanting to achieve with the above
code?
I'll push a patch.
The meta key items above were generated from the following code
{{{#!php
<?php
$new_post = wp_insert_post(
array(
'post_title' => 'Test Develop',
'post_name' => 'Test Develop',
'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:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list