コード例 #1
0
 public static function init()
 {
     add_action('set_object_terms', function ($post_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids) {
         $post_type = get_post_type($post_id);
         if (in_array($taxonomy, Lift_Taxonomy_Update_Watcher::get_watched_taxonomies($post_type))) {
             if ($append || array_diff($old_tt_ids, $tt_ids) || array_diff($tt_ids, $old_tt_ids)) {
                 lift_queue_field_update($post_id, 'taxonomy_' . $taxonomy, 'post');
             }
         }
     }, 10, 6);
     add_action('edited_term', function ($term_id, $tt_id, $taxonomy) {
         $watched_post_types = Lift_Post_Update_Watcher::get_watched_post_types();
         $tax_obj = get_taxonomy($taxonomy);
         $post_types = array_intersect($watched_post_types, $tax_obj->object_type);
         foreach ($post_types as $post_type) {
             if (in_array($taxonomy, Lift_Taxonomy_Update_Watcher::get_watched_taxonomies($post_type))) {
                 //we now have to update every post that has this term...dude, this sucks
                 $post_ids = get_posts(array('fields' => 'ids', 'posts_per_page' => 999, 'post_type' => $post_type, 'tax_query' => array(array('taxonomy' => $taxonomy, 'field' => 'id', 'terms' => $term_id))));
                 foreach ($post_id as $post_id) {
                     lift_queue_field_update($post_id, 'taxonomy_' . $taxonomy, 'post');
                 }
             }
         }
     }, 10, 3);
 }