Separate categories for all custom type post in wordpress. create custom post with multiple categories option in wordpress. please find sample code below
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | /*=======|Custom Post Type (Media)|======*/ function custom_post_type_media() { $labels = array( 'name' => __( 'Media Post' ), 'singular_name' => __( 'Media Post'), 'menu_name' => __( 'Media Posts'), 'parent_item_colon' => __( 'Parent Media Post'), 'all_items' => __( 'All Media Post'), 'view_item' => __( 'View Media Post'), 'add_new_item' => __( 'Add New Media Post'), 'add_new' => __( 'Add New'), 'edit_item' => __( 'Edit Media Post'), 'update_item' => __( 'Update Media Post'), 'search_items' => __( 'Search Media Post'), 'not_found' => __( 'Not Found'), 'not_found_in_trash' => __( 'Not found in Trash') ); $args = array( 'label' => __( 'media-post'), 'description' => __( 'Media Posts for news'), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'), 'public' => true, 'hierarchical' => false, 'show_ui' => true, 'show_in_menu' => true, 'menu_icon' => 'dashicons-welcome-view-site', 'show_in_nav_menus' => true, 'show_in_admin_bar' => true, 'has_archive' => true, 'can_export' => true, 'exclude_from_search' => false, 'yarpp_support' => true, 'taxonomies' => array('post_tag'), 'publicly_queryable' => true, 'capability_type' => 'page' ); register_post_type( 'media-post', $args ); } add_action( 'init', 'custom_post_type_media', 0 ); // Let us create Taxonomy for Custom Post Type add_action( 'init', 'custom_post_type_media_taxonomy', 0 ); //create a custom taxonomy name it "type" for your posts function custom_post_type_media_taxonomy() { $labels = array( 'name' => _x( 'Media Category', 'taxonomy general name' ), 'singular_name' => _x( 'Media Category', 'taxonomy singular name' ), 'search_items' => __( 'Search Types' ), 'all_items' => __( 'All Media Category' ), 'parent_item' => __( 'Parent Media Category' ), 'parent_item_colon' => __( 'Parent Media Category:' ), 'edit_item' => __( 'Edit Media Category' ), 'update_item' => __( 'Update Media Category' ), 'add_new_item' => __( 'Add New Media Category' ), 'new_item_name' => __( 'New Media Category Name' ), 'menu_name' => __( 'Media Category' ), ); register_taxonomy('media-category',array('media-post'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'show_admin_column' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'media-category' ), )); } |