Tuesday, 27 August 2013

Getting all post/page IDs related to a soon-to-be-deleted tag/cat

Getting all post/page IDs related to a soon-to-be-deleted tag/cat

When deleting a tag, category or other term I would like to get the IDs of
the posts that are related to the term before deletion. Wordpress uses
wp_delete_term, which is found in taxonomy.php, to delete a term. In this
function the earliest hook is "delete_term_taxonomy". However, it seems
like the relationships are already deleted before this hook fires.
I would like to make this query:
SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = $id
This would normally return all the post ids related to a term
(category/tag/etc). Is there any other hook I can use? Or maybe a hack?

No comments:

Post a Comment