Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hook into 'save custom taxonomy' like 'save_post' in WordPress

Is it possible to hook a function when a custom taxonomy term (which is not known beforehand), (preferably custom taxonomy child term) is edited/saved, just like the way we can hook into save_post when a post or page is saved?

What I want to do when the taxonomy term is saved:

function generate_pdf($slug) {
    wp_remote_get( etc... );
}

EDIT:

It seems that edit_${taxonomy} is the thing that I need, but I can't seem to push the $term_slug into the function:

function pdf_save_magazine($term_id, $tt_id, $taxonomy) {
    $term = get_term($term_id, $tt_id);
    $term_slug = $term->slug;
    wp_remote_get(
        'http://url-that-saves-pdf.com/?print='.$term_slug,
         array(
             'blocking' => false,
             'timeout' => 1,
             'httpversion' => '1.1'
          )
    );
}
add_action( 'edit_auteur', 'pdf_save_magazine', $term_id, $tt_id, $taxonomy );
like image 727
andyderuyter Avatar asked Sep 08 '15 12:09

andyderuyter


People also ask

How do I add custom taxonomy to WordPress?

In WordPress, you can create (or “register”) a new taxonomy by using the register_taxonomy() function. Each taxonomy option is documented in detail in the WordPress Codex. After adding this to your theme's functions. php file, you should see a new taxonomy under the “Posts” menu in the admin sidebar.

How do I display custom taxonomy in dropdown WordPress?

Add the following code into the “functions.$selected = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'ids')); $hierarchical = $tax->hierarchical; ?>

How do I show taxonomy terms in WordPress?

Displaying Custom Taxonomy Terms in a Widget Using Code First, you need to add this code in your theme's functions. php file or a site-specific plugin. add_filter( 'widget_text' , 'do_shortcode' );


1 Answers

To answer my own question:

This works:

function pdf_save_magazine($term_id, $tt_id, $taxonomy) {
   $term = get_term($term_id, $taxonomy);
   $term_slug = $term->slug;
    wp_remote_get(
      'http://url-that-saves-pdf.com/?print='.$term_slug,
      array(
         'blocking' => false,
         'timeout' => 1,
         'httpversion' => '1.1'
      )
   );
}
add_action( 'edit_term', 'pdf_save_magazine', 10, 3 );
like image 174
andyderuyter Avatar answered Sep 25 '22 09:09

andyderuyter