function create_chapter_post_type() { $labels = array( 'name' => _x( 'Chapters', 'Post Type General Name', 'text_domain' ), 'singular_name' => _x( 'Chapter', 'Post Type Singular Name', 'text_domain' ), 'menu_name' => __( 'Chapters', 'text_domain' ), 'name_admin_bar' => __( 'Chapter', 'text_domain' ), 'archives' => __( 'Chapter Archives', 'text_domain' ), 'parent_item_colon' => __( 'Chapter Group:', 'text_domain' ), 'all_items' => __( 'All Chapters', 'text_domain' ), 'add_new_item' => __( 'Add New Chapter', 'text_domain' ), 'add_new' => __( 'New Chapter', 'text_domain' ), 'new_item' => __( 'New Chapter', 'text_domain' ), 'edit_item' => __( 'Edit Chapter', 'text_domain' ), 'update_item' => __( 'Update Chapter', 'text_domain' ), 'view_item' => __( 'View Chapter', 'text_domain' ), 'search_items' => __( 'Search Chapters', 'text_domain' ), 'not_found' => __( 'Chapter not found', 'text_domain' ), 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), ); $args = array( 'label' => __( 'Chapter', 'text_domain' ), 'description' => __( 'Chapters post type', 'text_domain' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'post-formats', 'revisions', 'thumbnail', 'chapters_name', 'revisions' ), 'taxonomies' => array( 'chapter-type', 'rec-year' ), 'public' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-awards', 'show_in_admin_bar' => true, 'can_export' => true, 'has_archive' => true, 'query_var' => true, 'capability_type' => 'post', 'register_meta_box_cb' => 'add_chapters_metaboxes', 'rewrite' => array('slug' => 'chapter'), ); register_post_type( 'chapter', $args ); } add_action( 'init', 'create_chapter_post_type', 0 ); function create_chapter_tax() { $labels = array( 'name' => _x( 'Types', 'tables_to_repairxonomy general name' ), 'singular_name' => _x( 'Type', 'taxonomy singular name' ), 'search_items' => __( 'Search Types' ), 'popular_items' => __( 'Popular Types' ), 'all_items' => __( 'All Types' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Type' ), 'update_item' => __( 'Update Type' ), 'add_new_item' => __( 'Add New Type' ), 'new_item_name' => __( 'New Type Name' ), 'separate_items_with_commas' => __( 'Separate new types with commas' ), 'add_or_remove_items' => __( 'Add or remove types' ), 'choose_from_most_used' => __( 'Choose from the most used types' ), 'not_found' => __( 'No types found.' ), 'menu_name' => __( 'Types' ), ); $args = array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => 'chapter-type', 'rewrite' => array( 'slug' => 'chapter-type', 'with_front' => false ), ); register_taxonomy( 'chapter-type', 'chapter', $args ); $labelstwo = array( 'name' => _x( 'Years', 'tables_to_repairxonomy general name' ), 'singular_name' => _x( 'Year', 'taxonomy singular name' ), 'search_items' => __( 'Search Years' ), 'popular_items' => __( 'Popular Years' ), 'all_items' => __( 'All Years' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Year' ), 'update_item' => __( 'Update Year' ), 'add_new_item' => __( 'Add New Year' ), 'new_item_name' => __( 'New Year' ), 'separate_items_with_commas' => __( 'Separate new years with commas' ), 'add_or_remove_items' => __( 'Add or remove years' ), 'choose_from_most_used' => __( 'Choose from the most used years' ), 'not_found' => __( 'No years found.' ), 'menu_name' => __( 'Years' ), ); $argstwo = array( 'hierarchical' => true, 'labels' => $labelstwo, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => 'rec-year', 'rewrite' => array( 'slug' => 'timeframe', 'with_front' => false ), ); register_taxonomy( 'rec-year', 'chapter', $argstwo ); } add_action( 'init', 'create_chapter_tax' ); function add_chapters_metaboxes() { add_meta_box('chapters_name', 'Chapter Name', 'chapters_name', 'chapters', 'normal', 'default'); } add_action( 'add_meta_boxes_chapters', 'add_chapters_metaboxes'); function recipients_name_meta() { global $post; // Noncename needed to verify where the data originated echo '<input type="hidden" name="chaptersmeta_noncename" id="chaptersmeta_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; // Get the location data if its already been entered $name = get_post_meta($post->ID, '_name', true); // Echo out the field echo '<input type="text" name="_name" value="' . $name . '" class="widefat" />'; } //adds the taxonomy filter to the back-end display | example code taken frome here: http://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/ add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy'); function tsm_filter_post_type_by_taxonomy() { global $typenow; $post_type = 'chapter'; // change to your post type $taxonomy = 'chapter-type'; // change to your taxonomy if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' => __("Show All {$info_taxonomy->label}"), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } /** Filter posts by taxonomy in admin */ add_filter('parse_query', 'tsm_convert_id_to_term_in_query'); function tsm_convert_id_to_term_in_query($query) { global $pagenow; $post_type = 'chapter'; // change to your post type $taxonomy = 'chapter-type'; // change to your taxonomy $q_vars = &$query->query_vars; if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } } //SECOND adds the taxonomy filter to the back-end display | example code taken frome here: http://thestizmedia.com/custom-post-type-filter-admin-custom-taxonomy/ add_action('restrict_manage_posts', 'tsm_filter_post_type_by_taxonomy2'); function tsm_filter_post_type_by_taxonomy2() { global $typenow; $post_type = 'chapter'; // change to your post type $taxonomy = 'rec-year'; // change to your taxonomy if ($typenow == $post_type) { $selected = isset($_GET[$taxonomy]) ? $_GET[$taxonomy] : ''; $info_taxonomy = get_taxonomy($taxonomy); wp_dropdown_categories(array( 'show_option_all' => __("Show All {$info_taxonomy->label}"), 'taxonomy' => $taxonomy, 'name' => $taxonomy, 'orderby' => 'name', 'selected' => $selected, 'show_count' => true, 'hide_empty' => true, )); }; } /** Filter posts by taxonomy in admin */ add_filter('parse_query', 'tsm_convert_id_to_term_in_query2'); function tsm_convert_id_to_term_in_query2($query) { global $pagenow; $post_type = 'chapter'; // change to your post type $taxonomy = 'rec-year'; // change to your taxonomy $q_vars = &$query->query_vars; if ( $pagenow == 'edit.php' && isset($q_vars['post_type']) && $q_vars['post_type'] == $post_type && isset($q_vars[$taxonomy]) && is_numeric($q_vars[$taxonomy]) && $q_vars[$taxonomy] != 0 ) { $term = get_term_by('id', $q_vars[$taxonomy], $taxonomy); $q_vars[$taxonomy] = $term->slug; } }