Skip to content

Instantly share code, notes, and snippets.

@techjewel
Created November 4, 2015 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save techjewel/e8cf18612e34a33c3ca4 to your computer and use it in GitHub Desktop.
Save techjewel/e8cf18612e34a33c3ca4 to your computer and use it in GitHub Desktop.
Creating Custom Post Type with Custom Taxanomy
<?php
// Register Custom Post Type named FAQ
function wagon_faqs_post_type() {
$labels = array(
'name' => _x( 'CPAP FAQs', 'Post Type General Name', 'cpap' ),
'singular_name' => _x( 'CPAP FAQ', 'Post Type Singular Name', 'cpap' ),
'menu_name' => __( 'CPAP FAQs', 'cpap' ),
'name_admin_bar' => __( 'CPAP FAQs', 'cpap' ),
'parent_item_colon' => __( 'Parent FAQ:', 'cpap' ),
'all_items' => __( 'All FAQs', 'cpap' ),
'add_new_item' => __( 'Add New FAQ', 'cpap' ),
'add_new' => __( 'Add New FAQ', 'cpap' ),
'new_item' => __( 'New Item FAQ', 'cpap' ),
'edit_item' => __( 'Edit FAQ', 'cpap' ),
'update_item' => __( 'Update FAQ', 'cpap' ),
'view_item' => __( 'View FAQ', 'cpap' ),
'search_items' => __( 'Search FAQ', 'cpap' ),
'not_found' => __( 'Not found', 'cpap' ),
'not_found_in_trash' => __( 'Not found in Trash', 'cpap' ),
);
$args = array(
'label' => __( 'cpap_faq', 'cpap' ),
'description' => __( 'CPAP Video FAQs', 'cpap' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'comments', 'revisions' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'menu_icon' => 'dashicons-book'
);
register_post_type( 'cpap_faq', $args );
}
add_action('init', 'wagon_faqs_post_type');
// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_faq_taxonomies', 0 );
// create two taxonomies, genres and writers for the post type "book"
function create_faq_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'FAQ Categories', 'taxonomy general name' ),
'singular_name' => _x( 'FAQ Category', 'taxonomy singular name' ),
'search_items' => __( 'Search FAQ Category' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category Name' ),
'menu_name' => __( 'FAQ Category' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'faq-category' ),
);
register_taxonomy( 'faq-category', array( 'cpap_faq' ), $args );
// Add new taxonomy, NOT hierarchical (like tags)
$labels1 = array(
'name' => _x( 'FAQ Tags', 'taxonomy general name' ),
'singular_name' => _x( 'FAQ Tag', 'taxonomy singular name' ),
'search_items' => __( 'Search FAQ Tags' ),
'popular_items' => __( 'Popular FAQ Tags' ),
'all_items' => __( 'All FAQ Tags' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit FAQ Tag' ),
'update_item' => __( 'Update FAQ Tag' ),
'add_new_item' => __( 'Add New FAQ Tag' ),
'new_item_name' => __( 'New FAQ Tag Name' ),
'separate_items_with_commas' => __( 'Separate FAQ Tag with commas' ),
'add_or_remove_items' => __( 'Add or remove FAQ Tags' ),
'choose_from_most_used' => __( 'Choose from the most used FAQ Tags' ),
'not_found' => __( 'No FAQ Tag found.' ),
'menu_name' => __( 'FAQ Tags' ),
);
$args1 = array(
'hierarchical' => false,
'labels' => $labels1,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'faq-tag' ),
);
register_taxonomy( 'cpap_tags', array('cpap_faq'), $args1 );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment