Created
May 23, 2023 08:28
-
-
Save Danushka181/cc6987deaee3d55d642aefcc6d004b7c to your computer and use it in GitHub Desktop.
create post type with sub menues
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * circulars post type registration and category registration. | |
| * @since 1.0.0 | |
| */ | |
| function custom_post_type() { | |
| $labels = array( | |
| 'name' => 'Circulars', | |
| 'singular_name' => 'Circular', | |
| 'add_new' => 'Add New', | |
| 'add_new_item' => 'Add New Circular', | |
| 'edit_item' => 'Edit Circular', | |
| 'new_item' => 'New Circular', | |
| 'view_item' => 'View Circular', | |
| 'search_items' => 'Search Circulars', | |
| 'not_found' => 'No circulars found', | |
| 'not_found_in_trash' => 'No circulars found in Trash', | |
| 'parent_item_colon' => '', | |
| 'menu_name' => 'Circulars', | |
| ); | |
| $args = array( | |
| 'labels' => $labels, | |
| 'public' => true, | |
| 'publicly_queryable' => true, | |
| 'show_ui' => true, | |
| 'show_in_menu' => true, | |
| 'query_var' => true, | |
| 'rewrite' => array( 'slug' => 'circular' ), | |
| 'capability_type' => 'post', | |
| 'has_archive' => true, | |
| 'hierarchical' => false, | |
| 'menu_position' => 10, | |
| 'menu_icon' => 'dashicons-media-document', | |
| 'show_in_rest' => true, | |
| 'supports' => array( 'title', 'editor', 'author', 'thumbnail' ), | |
| ); | |
| register_post_type( 'circular', $args ); | |
| // Add categories taxonomy to circulars | |
| $taxonomy_labels = array( | |
| 'name' => 'Circular Types', | |
| 'singular_name' => 'Circular Type', | |
| 'search_items' => 'Search Circular Types', | |
| 'popular_items' => 'Popular Circular Types', | |
| 'all_items' => 'All Circular Types', | |
| 'parent_item' => 'Parent Circular Type', | |
| 'parent_item_colon' => 'Parent Circular Type:', | |
| 'edit_item' => 'Edit Circular Type', | |
| 'update_item' => 'Update Circular Type', | |
| 'add_new_item' => 'Add New Circular Type', | |
| 'new_item_name' => 'New Circular Type Name', | |
| 'separate_items_with_commas' => 'Separate circular types with commas', | |
| 'add_or_remove_items' => 'Add or remove circular types', | |
| 'choose_from_most_used' => 'Choose from the most used circular types', | |
| 'not_found' => 'No circular types found', | |
| 'menu_name' => 'Circular Types', | |
| ); | |
| $taxonomy_args = array( | |
| 'hierarchical' => true, | |
| 'labels' => $taxonomy_labels, | |
| 'show_ui' => true, | |
| 'show_admin_column' => true, | |
| 'query_var' => true, | |
| 'rewrite' => array( 'slug' => 'circular-type' ), | |
| ); | |
| register_taxonomy( 'circular_type', 'circular', $taxonomy_args ); | |
| } | |
| // Add submenu page for uploading circular documents | |
| function add_custom_submenu_page() { | |
| if (current_user_can('manage_options')) { | |
| add_submenu_page( | |
| 'edit.php?post_type=circular', | |
| 'Upload Circulars', | |
| 'Upload Circulars', | |
| 'manage_options', | |
| 'upload-circulars', | |
| 'upload_circulars_callback' | |
| ); | |
| } | |
| } | |
| function upload_circulars_callback() { | |
| // Callback function for the "Upload Documents" submenu page | |
| // Add your HTML and form handling logic here | |
| require_once trailingslashit( get_stylesheet_directory() ).'inc/Circulars/views/view-upload.php'; | |
| } | |
| add_action( 'init', 'custom_post_type' ); | |
| add_action( 'admin_menu', 'add_custom_submenu_page' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment