WordPress.org

Make WordPress Core

Opened 2 years ago

Closed 20 months ago

Last modified 16 months 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 Owned by: 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 23 months ago.
Fix doc comment of wp_insert_post and wp_set_post_categories.

Download all attachments as: .zip

Change History (9)

#1 @DrewAPicture
2 years ago

  • Description modified (diff)

#2 @DrewAPicture
2 years ago

  • Milestone changed from Awaiting Review to Future Release

@Takahashi_Fumiki
23 months ago

Fix doc comment of wp_insert_post and wp_set_post_categories.

#3 @Takahashi_Fumiki
23 months 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
23 months 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
23 months ago

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

#6 @pento
20 months ago

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

#7 @pento
20 months 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
16 months ago

#38435 was marked as a duplicate.

Note: See TracTickets for help on using tickets.