WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#10821 closed defect (bug) (fixed)

Taxonomy problem with deleting posts

Reported by: pavelevap Owned by: filosofo
Milestone: 2.9 Priority: high
Severity: major Version: 2.8
Component: Taxonomy Keywords: has-patch
Focuses: Cc:

Description

When I delete post, there are also deleted its relations to tags, categories, custom fields etc. But relations to taxonomy persists. So I can see on taxonomy page that there is post with parzticular taxonomy term, but this post no longer exist. The same problem is with function wp_delete_post().

Attachments (2)

ticket-10821.patch (652 bytes) - added by miqrogroove 4 years ago.
10821.diff (1.0 KB) - added by dd32 4 years ago.

Download all attachments as: .zip

Change History (15)

comment:1 miqrogroove4 years ago

  • Keywords reporter-feedback added

pavelevap, on which version of WordPress did you experience this problem?

comment:2 miqrogroove4 years ago

  • Keywords reporter-feedback removed
  • Severity changed from normal to major
  • Version set to 2.8

Confirmed 2.8.4 leaves orphaned rows in the term_relationships table when the term_taxonomy_id value belongs to any custom taxonomy. For example, if I delete post ID 41, there are still some rows with object_id 41.

comment:3 miqrogroove4 years ago

  • Keywords needs-patch added

See http://core.trac.wordpress.org/browser/trunk/wp-includes/post.php#L1189

/** @todo delete for pluggable post taxonomies too */
wp_delete_object_term_relationships($postid, array('category', 'post_tag'));

miqrogroove4 years ago

comment:4 miqrogroove4 years ago

  • Keywords has-patch added; needs-patch removed

comment:5 ryan4 years ago

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

(In [12299]) Delete custom taxonomy relationships when deleting a post. Props miqrogroove. fixes #10821

comment:6 dd324 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

wp_delete_attachment() needs the same treatment.

Also get_object_taxonomies($post->post_type) is better suited, as the function already handles posts/pages, and will handle custom post types this way.

comment:7 dd324 years ago

hit a slight issue with wp_delete_attachment... According to the Taxonomy system, category and post_tag do not get applied to Attachments, Yet, Categories get attached to ALL post types (ie. EVERY object in the posts table gets an attachment, Uncategorized if nothing specified)

As a result, i'm not sure what to do there, The proper thing would be to tell Taxonomy that the category tax applies to ALL objects, This however, has the disadvantage that, well, It doesnt apply to everything in practice.

So instead, I've just left wp_delete_attachment deleting category and post_tag anyway, and then a seperate call to delete custom tax's..

dd324 years ago

comment:8 dd324 years ago

Yet, Categories get attached to ALL post types (ie. EVERY object in the posts table gets an attachment, Uncategorized if nothing specified)

..And for that reason, wp_delete_post() should also specifically delete categories.. Not going to add a second patch for that, A commiter can merge that in..

comment:9 dd324 years ago

wp_delete_post() should also specifically delete categories..

Because it deleted custom post_type's which may have a category, or at least, an Uncategorized category.

comment:10 ryan4 years ago

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

(In [12305]) Delete custom taxonomy relationships when deleting a post or attachment. Props dd32. fixes #10821

comment:11 miqrogroove4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

$postid is uninitialized. Do not pass go, do not collect $200 ;)

comment:12 ryan4 years ago

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

(In [12307]) Use correct var name. Props miqrogroove. fixes #10821

comment:13 dd324 years ago

This still doesnt delete the category tax for non-category-registered-types.

ie. anything custom inserted with wp_insert_post will be assigned a category, Therefor, Anything deleted with wp_delete_post needs to delete any category terms->object terms no matter the post type.

Note: See TracTickets for help on using tickets.