Created
July 12, 2023 03:28
-
-
Save chekle/4c9c9eacfd4601003a2d51840b76ad4b to your computer and use it in GitHub Desktop.
WordPress Register Custom Post Type & Taxonomy
This file contains 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
function my_custom_post_projects() { | |
$labels = array( | |
'name' => _x( 'Projects', 'post type general name' ), | |
'singular_name' => _x( 'Project', 'post type singular name' ), | |
'add_new' => _x( 'Add New', 'Project' ), | |
'add_new_item' => __( 'Add New Project' ), | |
'edit_item' => __( 'Edit Project' ), | |
'new_item' => __( 'New Project' ), | |
'all_items' => __( 'All Projects' ), | |
'view_item' => __( 'View Project' ), | |
'search_items' => __( 'Search Projects' ), | |
'not_found' => __( 'No Projects found' ), | |
'not_found_in_trash' => __( 'No Projects found in the Trash' ), | |
'parent_item_colon' => '', | |
'menu_name' => 'Projects' | |
); | |
$args = array( | |
'labels' => $labels, | |
'description' => 'Holds Projects and Project data', | |
'public' => true, | |
//'publicly_queryable' => false, | |
'menu_position' => 2, | |
//'taxonomies' => array('post_tag'), | |
'rewrite' => array('slug' => 'projects', 'with_front' => false), | |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ), | |
//'show_in_rest' => true, | |
'has_archive' => true, | |
); | |
register_post_type( 'projects', $args ); | |
} | |
add_action( 'init', 'my_custom_post_projects' ); | |
function my_taxonomies_projects() { | |
$labels = array( | |
'name' => _x( 'Project Categories', 'taxonomy general name' ), | |
'singular_name' => _x( 'Project Category', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Project Categories' ), | |
'all_items' => __( 'All Project Categories' ), | |
'parent_item' => __( 'Parent Project Category' ), | |
'parent_item_colon' => __( 'Parent Project Category:' ), | |
'edit_item' => __( 'Edit Project Category' ), | |
'update_item' => __( 'Update Project Category' ), | |
'add_new_item' => __( 'Add New Project Category' ), | |
'new_item_name' => __( 'New Project Category' ), | |
'menu_name' => __( 'Project Categories' ), | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'show_admin_column' => true, | |
//'show_in_rest' => true, | |
); | |
register_taxonomy( 'projects_category', 'projects', $args ); | |
} | |
add_action( 'init', 'my_taxonomies_projects', 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment