Make WordPress Core

Opened 17 years ago

Closed 17 years ago

Last modified 17 years ago

#10821 closed defect (bug) (fixed)

Taxonomy problem with deleting posts

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

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 17 years ago.
10821.diff (1.0 KB ) - added by dd32 17 years ago.

Download all attachments as: .zip

Change History (15)

#1 @miqrogroove
17 years ago

  • Keywords reporter-feedback added

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

#2 @miqrogroove
17 years ago

  • Keywords reporter-feedback removed
  • Severity normalmajor
  • Version2.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.

#3 @miqrogroove
17 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'));

#4 @miqrogroove
17 years ago

  • Keywords has-patch added; needs-patch removed

#5 @ryan
17 years ago

  • Resolutionfixed
  • Status newclosed

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

#6 @dd32
17 years ago

  • Resolution fixed
  • Status closedreopened

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.

#7 @dd32
17 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..

@dd32
17 years ago

#8 @dd32
17 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..

#9 @dd32
17 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.

#10 @ryan
17 years ago

  • Resolutionfixed
  • Status reopenedclosed

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

#11 @miqrogroove
17 years ago

  • Resolution fixed
  • Status closedreopened

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

#12 @ryan
17 years ago

  • Resolutionfixed
  • Status reopenedclosed

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

#13 @dd32
17 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.