array( 'name' => ucwords($shortname).__(' Project', 'biznez' ), 'singular_name' => __( 'project', 'biznez' ), 'add_new' => __('Add Project', 'biznez'), 'add_new_item' => __('Add New Project', 'biznez'), 'edit_item' => __('Edit Project', 'biznez'), 'new_item' => __('New Project', 'biznez'), 'all_items' => __('All Projects', 'biznez'), 'view_item' => __('View Project', 'biznez') ), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_icon' => get_template_directory_uri().'/images/custom_project.png', 'rewrite' => array('slug' => 'project'), 'supports' => array('title','thumbnail','editor'), 'taxonomies'=>array('project_category','project_tag') )); } function project_category_init() { // create a new taxonomy register_taxonomy( 'project_category', 'project', array( 'hierarchical' => true, 'label' => __( 'Project Categories', 'biznez' ), 'singular_label' => __( 'Project Category', 'biznez' ), 'rewrite' => array( 'slug' => 'project_category') ) ); } add_action( 'init', 'project_category_init' ); function project_tag_init() { // create a new taxonomy register_taxonomy( 'project_tag', 'project', array( 'label' => __( 'Project Tags', 'biznez' ), 'singular_label' => __( 'Project Tag', 'biznez' ), 'rewrite' => array( 'slug' => 'project_tag') ) ); } add_action( 'init', 'project_tag_init' ); function skt_wp_default_terms(){ $parent_term = term_exists( 'all projects', 'project_category' ); // array is returned if taxonomy is given $parent_term_id = $parent_term['term_id']; // get numeric term id if ($parent_term == 0 && $parent_term == null) { wp_insert_term( 'all projects', // the term 'project_category', // the taxonomy array( 'description'=> 'all projects.', 'slug' => 'all_projects', 'parent'=> $parent_term_id ) ); } } add_action( 'init', 'skt_wp_default_terms' ); function skt_set_default_object_terms( $post_id, $post ) { if ( 'publish' === $post->post_status ) { $defaults = array( 'project_category' => array( 'all_projects' ), ); $taxonomies = get_object_taxonomies( $post->post_type ); foreach ( (array) $taxonomies as $taxonomy ) { $terms = wp_get_post_terms( $post_id, $taxonomy ); if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) { wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy ); } } } } add_action( 'save_post', 'skt_set_default_object_terms', 100, 2 );