Created
April 16, 2018 06:18
-
-
Save ridhamdholakia/dafdc11620d6cc3a6ce535e50ca89906 to your computer and use it in GitHub Desktop.
Wordpress Custom Post with Custom Taxonomy
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
/* ======================================== Custom Post ============================================= */ | |
function education_post() { | |
$labels = array( | |
'name' => _x( 'Education Blogs', 'Post Type General Name', 'text_domain' ), | |
'singular_name' => _x( 'Education Blog', 'Post Type Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Education Blogs', 'text_domain' ), | |
'parent_item_colon' => __( 'Parent Education Blog:', 'text_domain' ), | |
'all_items' => __( 'All Education Blogs', 'text_domain' ), | |
'view_item' => __( 'View Education Blog', 'text_domain' ), | |
'add_new_item' => __( 'Add New Education Blog', 'text_domain' ), | |
'add_new' => __( 'Add New Education Blog', 'text_domain' ), | |
'edit_item' => __( 'Edit Education Blog', 'text_domain' ), | |
'update_item' => __( 'Update Education Blog', 'text_domain' ), | |
'search_items' => __( 'Search Education Blog', 'text_domain' ), | |
'not_found' => __( 'Not found', 'text_domain' ), | |
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ), | |
); | |
$args = array( | |
'label' => __( 'Education Blogs', 'text_domain' ), | |
'description' => __( 'Education Blog Description', 'text_domain' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'post-formats', 'custom-fields', 'comments', 'revisions' ), | |
'taxonomies' => array( 'education_categories' ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'show_in_admin_bar' => true, | |
'menu_icon' => 'dashicons-welcome-learn-more', | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'page', | |
); | |
register_post_type( 'education_blog', $args ); | |
} | |
add_action( 'init', 'education_post', 0 ); | |
/* ======================================== Custom Post taxonomy ============================================= */ | |
function themes_taxonomy() { | |
register_taxonomy( | |
'education_categories', | |
'education_blog', | |
array( | |
'hierarchical' => true, | |
'label' => 'Blog Categories', | |
'query_var' => true, | |
'rewrite' => array( | |
'slug' => 'blog-categories', | |
'with_front' => false | |
) | |
) | |
); | |
} | |
add_action( 'init', 'themes_taxonomy'); | |
/* ======================================== Custom Post taxonomy ============================================= */ | |
add_action( 'init', 'create_tag_taxonomies', 0 ); | |
function create_tag_taxonomies() | |
{ | |
$labels = array( | |
'name' => _x( 'Blog Tags', 'taxonomy general name' ), | |
'singular_name' => _x( 'Blog Tag', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Blog Tags' ), | |
'popular_items' => __( 'Popular Blog Blog Tags' ), | |
'all_items' => __( 'All Blog Tags' ), | |
'parent_item' => null, | |
'parent_item_colon' => null, | |
'edit_item' => __( 'Edit Blog Tag' ), | |
'update_item' => __( 'Update Blog Tag' ), | |
'add_new_item' => __( 'Add New Blog Tag' ), | |
'new_item_name' => __( 'New Blog Tag Name' ), | |
'separate_items_with_commas' => __( 'Separate Blog tags with commas' ), | |
'add_or_remove_items' => __( 'Add or remove Blog tags' ), | |
'choose_from_most_used' => __( 'Choose from the most used tags' ), | |
'menu_name' => __( 'Blog Tags' ), | |
); | |
register_taxonomy('blog_tags','education_blog',array( | |
'hierarchical' => false, | |
'labels' => $labels, | |
'show_ui' => true, | |
'update_count_callback' => '_update_post_term_count', | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'blog-tag' ), | |
)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment