Inserting Taxonomy Terms During a Plugin Activation?

Here is the fixed version of your code.

class vsetup {
     function __construct() {
          register_activation_hook(__FILE__,array($this,'activate'));
          add_action( 'init', array( $this, 'create_taxonomies' ) );
     } 
     function activate() {
          $this->create_taxonomies();
          wp_insert_term('Action','genre');
          wp_insert_term('Adventure','genre');
     }
     function create_taxonomies() {
           $genre_args = array( 
            'hierarchical' => true,  
                'labels' => array(
            'name'=> _x('Genres', 'taxonomy general name' ),
            'singular_name' => _x('Genre', 'taxonomy singular name'),
            'search_items' => __('Search Genres'),
            'popular_items' => __('Popular Genres'),
            'all_items' => __('All Genres'),
            'edit_item' => __('Edit Genre'),
            'edit_item' => __('Edit Genre'),
            'update_item' => __('Update Genre'),
            'add_new_item' => __('Add New Genre'),
            'new_item_name' => __('New Genre Name'),
            'separate_items_with_commas' => __('Seperate Genres with Commas'),
            'add_or_remove_items' => __('Add or Remove Genres'),
            'choose_from_most_used' => __('Choose from Most Used Genres')
            ),  
                'query_var' => true,  
            'rewrite' => array('slug' =>'genre')        
           );
           register_taxonomy('genre', 'post',$genre_args);
     }
}

And don’t forget to create the object/instance of the vsetup class i.e new vsetup()

Huh! Forgot to remove the debug statement.

Leave a Comment