Skip to content

Instantly share code, notes, and snippets.

@gagimilicevic
Created November 10, 2016 15:10
Show Gist options
  • Save gagimilicevic/09f21cfff76909f913238547fb70557a to your computer and use it in GitHub Desktop.
Save gagimilicevic/09f21cfff76909f913238547fb70557a to your computer and use it in GitHub Desktop.
Create CPT and Custom Taxonomy for CPT
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'faq',
array(
'labels' => array(
'name' => __( 'FAQ' ),
'singular_name' => __( 'FAQ' )
),
'public' => true,
'has_archive' => false,
'taxonomies' => array( 'faq_category' ),
)
);
}
/**
* faqs_hierarchical_taxonomy
*/
add_action( 'init', 'faq_hierarchical_taxonomy', 0 );
function faq_hierarchical_taxonomy() {
$labels = array(
'name' => _x( 'FAQ Categories', 'taxonomy general name' ),
'singular_name' => _x( 'FAQ', 'taxonomy singular name' ),
'search_items' => __( 'Search FAQs' ),
'popular_items' => __( 'Popular FAQs' ),
'all_items' => __( 'All FAQs' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit FAQ' ),
'update_item' => __( 'Update FAQ' ),
'add_new_item' => __( 'Add New FAQ' ),
'new_item_name' => __( 'New FAQ Name' ),
'separate_items_with_commas' => __( 'Separate FAQs with commas' ),
'add_or_remove_items' => __( 'Add or remove FAQs' ),
'choose_from_most_used' => __( 'Choose from the most used FAQs' ),
'menu_name' => __( 'FAQ Category' ),
);
register_taxonomy('faqs_category','faq',array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'query_var' => true,
'rewrite' => array( 'slug' => 'faq_category' ),
));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment