Make WordPress Core

Opened 12 years ago

Closed 9 years ago

Last modified 9 years ago

#20451 closed enhancement (fixed)

wp_insert_post() should accept a meta_input argument

Reported by: johnbillion's profile johnbillion Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: low
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch commit
Focuses: Cc:

Description

wp_insert_post() accepts a tax_input argument to set the post's terms, but there's no similar argument to set the post's meta fields. add_post_meta() must be called for each meta field after wp_insert_post() is called.

I'll do up a patch at some point.

Attachments (2)

20451.diff (464 bytes) - added by CoenJacobs 12 years ago.
Basic fix that loops through provided meta fields and values
20451.2.diff (1.7 KB) - added by swissspidy 9 years ago.

Download all attachments as: .zip

Change History (9)

@CoenJacobs
12 years ago

Basic fix that loops through provided meta fields and values

#1 @CoenJacobs
12 years ago

Provided patch proves that it can be done really easy. This patch does not check for capabilities and there is lots of room for improvement. Just showing how easy it can be.

Now on to if it should be done and what we need to consider before doing so.

#2 @Funkatronic
10 years ago

Surprised this isn't implemented, especially with the meta field initiative going on.

@swissspidy
9 years ago

#3 @swissspidy
9 years ago

  • Keywords has-patch added
  • Milestone changed from Awaiting Review to 4.4

20451.2.diff is an updated patch that also updates the docblock for wp_insert_post and includes a unit test for the newly added meta_input parameter.

#4 @SergeyBiryukov
9 years ago

  • Keywords commit added

#5 @wonderboymusic
9 years ago

ok - devs need to use register_meta() to sanitize these values

#6 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 33910:

Allow wp_insert_post() to accept a meta_input argument. Devs should use register_meta() to ensure that specific values specified by key are sanitized properly.

Adds unit test.

Props CoenJacobs, swissspidy.
Fixes #20451.

#7 @johnbillion
9 years ago

In 33922:

Function docs for the tax_input and meta_input parameters available for wp_insert_post().

See #20451

Note: See TracTickets for help on using tickets.