Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- 1. Add at least one custom taxonomy
- 2. Create few pages with some kind of parent-child structure.
- eg:
- root
- -child1
- -child3
- -child4
- -child5
- -child2
- -child6
- 3.Enable polylang cpt support for this post type
- 4.Select all pages for bulk edit and assign the custom taxonomy to all selected pages
- 5.Re-check the page structure
- */
- // Register Custom Post Type
- function cpts() {
- $labels = array(
- 'name' => _x( 'Custom Post Type Pages', 'Post Type General Name', 'cpts' ),
- 'singular_name' => _x( 'Custom Post Type Page', 'Post Type Singular Name', 'cpts' ),
- 'menu_name' => __( 'Custom Post Type', 'cpts' ),
- 'name_admin_bar' => __( 'Custom Post Type', 'cpts' ),
- 'archives' => __( 'Item Archives', 'cpts' ),
- 'attributes' => __( 'Item Attributes', 'cpts' ),
- 'parent_item_colon' => __( 'Parent Item:', 'cpts' ),
- 'all_items' => __( 'All Items', 'cpts' ),
- 'add_new_item' => __( 'Add New Item', 'cpts' ),
- 'add_new' => __( 'Add New', 'cpts' ),
- 'new_item' => __( 'New Item', 'cpts' ),
- 'edit_item' => __( 'Edit Item', 'cpts' ),
- 'update_item' => __( 'Update Item', 'cpts' ),
- 'view_item' => __( 'View Item', 'cpts' ),
- 'view_items' => __( 'View Items', 'cpts' ),
- 'search_items' => __( 'Search Item', 'cpts' ),
- 'not_found' => __( 'Not found', 'cpts' ),
- 'not_found_in_trash' => __( 'Not found in Trash', 'cpts' ),
- 'featured_image' => __( 'Featured Image', 'cpts' ),
- 'set_featured_image' => __( 'Set featured image', 'cpts' ),
- 'remove_featured_image' => __( 'Remove featured image', 'cpts' ),
- 'use_featured_image' => __( 'Use as featured image', 'cpts' ),
- 'insert_into_item' => __( 'Insert into item', 'cpts' ),
- 'uploaded_to_this_item' => __( 'Uploaded to this item', 'cpts' ),
- 'items_list' => __( 'Items list', 'cpts' ),
- 'items_list_navigation' => __( 'Items list navigation', 'cpts' ),
- 'filter_items_list' => __( 'Filter items list', 'cpts' ),
- );
- $rewrite = array(
- 'slug' => 'help',
- 'with_front' => false,
- 'pages' => true,
- 'feeds' => true,
- );
- $args = array(
- 'label' => __( 'Custom Post Type Page', 'cpts' ),
- 'description' => __( 'Custom Post Type Pages', 'cpts' ),
- 'labels' => $labels,
- 'supports' => array( 'title', 'editor', 'revisions', 'page-attributes' ),
- 'taxonomies' => array( 'cpt_some_category' ),
- 'hierarchical' => true,
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'menu_position' => 5,
- 'menu_icon' => 'dashicons-welcome-learn-more',
- 'show_in_admin_bar' => true,
- 'show_in_nav_menus' => true,
- 'can_export' => true,
- 'has_archive' => false,
- 'exclude_from_search' => false,
- 'publicly_queryable' => true,
- 'rewrite' => $rewrite,
- 'capability_type' => 'page',
- );
- register_post_type( 'cpts', $args );
- }
- add_action( 'init', 'cpts', 0 );
- // Register Custom Taxonomy
- function cpt_taxonomy() {
- $labels = array(
- 'name' => _x( 'Custom Post Type Categories', 'Taxonomy General Name', 'cpts' ),
- 'singular_name' => _x( 'Custom Post Type Category', 'Taxonomy Singular Name', 'cpts' ),
- 'menu_name' => __( 'Custom Post Type Category', 'cpts' ),
- 'all_items' => __( 'All Items', 'cpts' ),
- 'parent_item' => __( 'Parent Item', 'cpts' ),
- 'parent_item_colon' => __( 'Parent Item:', 'cpts' ),
- 'new_item_name' => __( 'New Item Name', 'cpts' ),
- 'add_new_item' => __( 'Add New Item', 'cpts' ),
- 'edit_item' => __( 'Edit Item', 'cpts' ),
- 'update_item' => __( 'Update Item', 'cpts' ),
- 'view_item' => __( 'View Item', 'cpts' ),
- 'separate_items_with_commas' => __( 'Separate items with commas', 'cpts' ),
- 'add_or_remove_items' => __( 'Add or remove items', 'cpts' ),
- 'choose_from_most_used' => __( 'Choose from the most used', 'cpts' ),
- 'popular_items' => __( 'Popular Items', 'cpts' ),
- 'search_items' => __( 'Search Items', 'cpts' ),
- 'not_found' => __( 'Not Found', 'cpts' ),
- 'no_terms' => __( 'No items', 'cpts' ),
- 'items_list' => __( 'Items list', 'cpts' ),
- 'items_list_navigation' => __( 'Items list navigation', 'cpts' ),
- );
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => true,
- 'public' => false,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'show_in_nav_menus' => false,
- 'show_tagcloud' => false,
- );
- register_taxonomy( 'cpt_some_category', array( 'cpts' ), $args );
- }
- add_action( 'init', 'cpt_taxonomy', 0 );
Add Comment
Please, Sign In to add comment