WordPress.org

Make WordPress Core

Opened 8 years ago

Last modified 5 months ago

#19954 reviewing defect (bug)

wp_insert_post overwrites categories when updating existing post

Reported by: markoheijnen Owned by: joehoyle
Milestone: Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: Cc:
PR Number:

Description

When creating an post object with get_default_post_to_edit(), wp_insert_post() will ignored the set category.
It doesn't look if the post has already a good category.

Attachments (2)

19954.patch (1.0 KB) - added by markoheijnen 8 years ago.
Does fix the issue. Maybe need better formating
19954.diff (3.7 KB) - added by leewillis77 3 years ago.
Patch

Download all attachments as: .zip

Change History (13)

@markoheijnen
8 years ago

Does fix the issue. Maybe need better formating

#1 @nacin
8 years ago

  • Milestone changed from Awaiting Review to 3.4

#2 @hughwillfayle
8 years ago

  • Cc t.herzog@… added

Why should this be? WordPress sets category to the default one if there hasn't been setted one.

#3 @jkudish
8 years ago

  • Keywords has-patch added

#4 @nacin
8 years ago

Could we have some example code that triggers this?

Is this an issue to fix/benefit XML-RPC changes in 3.4 at this point?

#5 @markoheijnen
8 years ago

I don't believe it is xml-rpc related. What I did was adding the category with the metod wp_set_object_terms() on the post ID what you get from get_default_post_to_edit(). I know thisis a rare condition.

#6 @ryan
7 years ago

  • Milestone changed from 3.4 to Future Release

#7 @markoheijnen
7 years ago

#22220 was marked as a duplicate.

#8 @chriscct7
4 years ago

  • Keywords needs-refresh added

@leewillis77
3 years ago

Patch

#9 @leewillis77
3 years ago

  • Keywords has-unit-tests added; needs-refresh removed

Hi;

I just hit this bug in a project. The issue is that if you call wp_insert_post() with an existing post ID, and do not supply post_category then any categories assigned to the post will be removed and replaced with the default category.

Patch with unit tests attached.

#10 @leewillis77
3 years ago

  • Summary changed from wp_insert_post should look if default category is nessesary to wp_insert_post overwrites categories when updating existing post

#11 @joehoyle
3 years ago

  • Owner set to joehoyle
  • Status changed from new to reviewing
Note: See TracTickets for help on using tickets.