Last active
December 9, 2021 14:48
-
-
Save iamandrewpeters/a84c1cba7aefd9fab01208c2712c7bd5 to your computer and use it in GitHub Desktop.
Resource Library CPT and Tax
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
//Create Resource Post Type | |
function register_my_resources_cpt() { | |
$labels = array( | |
"name" => __( "Resources", "" ), | |
"singular_name" => __( "Resource", "" ), | |
); | |
$args = array( | |
"label" => __( "Resources", "" ), | |
"labels" => $labels, | |
"description" => "Add resources/downloads. ", | |
"public" => true, | |
"publicly_queryable" => true, | |
"show_ui" => true, | |
"delete_with_user" => false, | |
"show_in_rest" => true, // If you are not using Gutenberg change this to false | |
"rest_base" => "", | |
"rest_controller_class" => "WP_REST_Posts_Controller", | |
"has_archive" => true, | |
"show_in_menu" => true, | |
"show_in_nav_menus" => true, | |
"exclude_from_search" => true, | |
"capability_type" => "post", | |
"map_meta_cap" => true, | |
"hierarchical" => false, | |
"rewrite" => array( "slug" => "resources", "with_front" => true ), | |
"query_var" => true, | |
"menu_position" => 5, | |
"menu_icon" => 'dashicons-image-filter', | |
"supports" => array( "title", "editor", "excerpt", "revisions", "author", "page-attributes", "post-formats" ), | |
); | |
register_post_type( "resources", $args ); | |
} | |
add_action( 'init', 'register_my_resources_cpt' ); |
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
// Register Resource Type Taxonomy | |
function resource_type_taxonomy_creation() { | |
$labels = array( | |
'name' => _x( 'Resource Types', 'Taxonomy General Name', 'text_domain' ), | |
'singular_name' => _x( 'Resource Type', 'Taxonomy Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Resource Type', 'text_domain' ), | |
'all_items' => __( 'All Resource Types', 'text_domain' ), | |
'parent_item' => __( 'Parent Resource Type', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Resource Type:', 'text_domain' ), | |
'new_item_name' => __( 'New Item Resource', 'text_domain' ), | |
'add_new_item' => __( 'Add New Resource Type', 'text_domain' ), | |
'edit_item' => __( 'Edit Resource Type', 'text_domain' ), | |
'update_item' => __( 'Update Resource Type', 'text_domain' ), | |
'view_item' => __( 'View Resource Type', 'text_domain' ), | |
'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ), | |
'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ), | |
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ), | |
'popular_items' => __( 'Popular Resource Type', 'text_domain' ), | |
'search_items' => __( 'Search Resource Types', 'text_domain' ), | |
'not_found' => __( 'Not Found', 'text_domain' ), | |
'no_terms' => __( 'No Resource Types', 'text_domain' ), | |
'items_list' => __( 'Resource Type list', 'text_domain' ), | |
'items_list_navigation' => __( 'Resource Type list navigation', 'text_domain' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
'show_in_rest' => true, | |
); | |
register_taxonomy( 'resource_type_tax', array( 'resources' ), $args ); | |
} | |
add_action( 'init', 'resource_type_taxonomy_creation', 0 ); | |
// Register Toolbox Category Taxonomy | |
function toolbox_cat_taxonomy_creation() { | |
$labels = array( | |
'name' => _x( 'Toolbox Categories', 'Taxonomy General Name', 'text_domain' ), | |
'singular_name' => _x( 'Toolbox Category', 'Taxonomy Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Toolbox Category', 'text_domain' ), | |
'all_items' => __( 'All Toolbox Categories', 'text_domain' ), | |
'parent_item' => __( 'Parent Toolbox Category', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Toolbox Category:', 'text_domain' ), | |
'new_item_name' => __( 'New Toolbox Categories', 'text_domain' ), | |
'add_new_item' => __( 'Add New Toolbox Category', 'text_domain' ), | |
'edit_item' => __( 'Edit Toolbox Category', 'text_domain' ), | |
'update_item' => __( 'Update Toolbox Category', 'text_domain' ), | |
'view_item' => __( 'View Toolbox Categories', 'text_domain' ), | |
'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ), | |
'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ), | |
'choose_from_most_used' => __( 'Choose from the most used', 'text_domain' ), | |
'popular_items' => __( 'Popular Toolbox Category', 'text_domain' ), | |
'search_items' => __( 'Search Toolbox Category', 'text_domain' ), | |
'not_found' => __( 'Not Found', 'text_domain' ), | |
'no_terms' => __( 'No Toolbox Categories', 'text_domain' ), | |
'items_list' => __( 'Toolbox Category list', 'text_domain' ), | |
'items_list_navigation' => __( 'Toolbox Category list navigation', 'text_domain' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
'show_in_rest' => true, | |
); | |
register_taxonomy( 'toolbox_type_type_tax', array( 'resources' ), $args ); | |
} | |
add_action( 'init', 'toolbox_cat_taxonomy_creation', 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment