Make WordPress Core

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#45171 closed defect (bug) (fixed)

Adjust wp_insert_post() docs to reflect that the post_category argument will only accept one or more term IDs

Reported by: drewapicture's profile DrewAPicture Owned by: pento's profile pento
Milestone: 5.1 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: good-first-bug has-patch
Focuses: docs Cc:

Description (last modified by DrewAPicture)

As pointed out by @ck-macleod on the Code Reference, the post_category argument for wp_insert_post() actually only accepts term IDs and not an "Array of category names, slugs, or IDs."

This is due to how adding hierarchical taxonomies terms (like categories) works up the stack in wp_insert_post() -> wp_set_post_categories() -> wp_set_post_terms().

 *     @type array  $post_category         Array of category names, slugs, or IDs.

The fix should remove reference to "names" and "slugs" in the $post_category entry in the hash notation for wp_insert_post().

Attachments (1)

45171.patch (1.5 KB) - added by Takahashi_Fumiki 5 years ago.
Fix doc comment of wp_insert_post and wp_set_post_categories.

Download all attachments as: .zip

Change History (9)

#1 @DrewAPicture
5 years ago

  • Description modified (diff)

#2 @DrewAPicture
5 years ago

  • Milestone changed from Awaiting Review to Future Release

5 years ago

Fix doc comment of wp_insert_post and wp_set_post_categories.

#3 @Takahashi_Fumiki
5 years ago

  • Keywords has-patch added

Fix doc comment of wp_insert_post.
Besides that, doc comment of wp_set_post_categories is also vague(List of categories), so I fixed it's more concrete List of category IDs.

#4 @DrewAPicture
5 years ago

  • Milestone changed from Future Release to 5.1
  • Owner set to Takahashi_Fumiki
  • Status changed from new to assigned

Assigning to mark the good-first-bug as "claimed".

Hi @Takahashi_Fumiki, thanks for the patch! Everything looks good here.

Trunk development is still closed pending the 5.0 release, but we should be able to get this in with 5.1.

#5 @Takahashi_Fumiki
5 years ago

@DrewAPicture Thanks for your rebiew! I got what you said:)

#6 @pento
5 years ago

  • Owner changed from Takahashi_Fumiki to pento
  • Status changed from assigned to accepted

#7 @pento
5 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 44660:

Docs: Improve the docblocks for wp_insert_post() and wp_set_post_categories().

Their respective post_category and post_categories parameters were not correct.

Props Takahashi_Fumiki.
Fixes #45171.

#8 @Hareesh Pillai
5 years ago

#38435 was marked as a duplicate.

Note: See TracTickets for help on using tickets.