[wp-hackers] Get Term Data Before Deletion

Ryan Fitzer ryanfitzer at gmail.com
Mon Sep 13 02:01:12 UTC 2010


Nice! Works like a charm. Thanks soo much Mike.

On Sun, Sep 12, 2010 at 6:19 PM, Mike Schinkel
<mikeschinkel at newclarity.net> wrote:
>> I'm using the delete_{$taxonomy} hook so when a term gets deleted I
>> can update my theme's options. The problem is that I need the slug. By
>> the time delete_{$taxonomy} runs, the term has been deleted from the
>> db (taxonomy.php line 1406). This means get_term() can't retrieve the
>> term slug.
>
> Yes, it would seem that would be quite the problem.  Doesn't seem like delete_{$taxonomy} would be all that useful without at least access to the term as it was before deletion?  Anyway...
>
> Try the "delete_term_taxonomy" hook.  It get's a term_taxonomy_id and reading the code it seems from that you can get the term_id and look it up before the term is deleted.  Unfortunately there doesn't appear to be an API call that will look up a taxonomy via a term_taxonomy_id (unless I missed it?) so you'll have to revert to raw SQL.  Try this:
>
> add_action('delete_term_taxonomy','grab_term_slug_on_delete');
> function grab_term_slug_on_delete($term_taxonomy_id) {
>        global $wpdb;
>        $sql = "SELECT t.slug FROM wp_terms t INNER JOIN wp_term_taxonomy tt ON t.term_id = tt.term_id WHERE term_taxonomy_id=%d";
>        $term_slug = $wpdb->get_var($wpdb->prepare($sql,$term_taxonomy_id));
>        // Do something with $term_slug here...
>        return;
> }
>
> Hope this helps.
>
> -Mike
>
>
> On Sep 12, 2010, at 8:54 PM, Ryan Fitzer wrote:
>
>> I'm trying to find a hook that will give me a term's slug before it is deleted.
>>
>> I'm using the delete_{$taxonomy} hook so when a term gets deleted I
>> can update my theme's options. The problem is that I need the slug. By
>> the time delete_{$taxonomy} runs, the term has been deleted from the
>> db (taxonomy.php line 1406). This means get_term() can't retrieve the
>> term slug.
>>
>> Anyone know of a way around this?
>>
>> --
>> Ryan Fitzer
>> Los Angeles, CA
>> http://www.ryanpatrickfitzer.com
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>



-- 
Ryan Fitzer
Los Angeles, CA
http://www.ryanfitzer.com
http://www.portfoliorodeo.com


More information about the wp-hackers mailing list