Skip to content

Instantly share code, notes, and snippets.

@itzikbenh
Last active January 9, 2020 20:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itzikbenh/8da0ea6ed0ed04c8662e1faace04485b to your computer and use it in GitHub Desktop.
Save itzikbenh/8da0ea6ed0ed04c8662e1faace04485b to your computer and use it in GitHub Desktop.
Custom taxonomy
<?php
function ath_register_event_taxonomies()
{
$ath_taxonomy = new Ath_Taxonomy();
$ath_taxonomy->create_hierarchical_taxonomy( "event", "event_category", "Event Categories", "Event Category", "event-category" );
$ath_taxonomy->create_taxonomy( "event", "event_tag", "Event Tags", "Event Tag", "event-tag" );
}
add_action( 'init', 'ath_register_event_taxonomies' );
<?php
class Ath_Taxonomy
{
//Will create category like taxonomy
function create_hierarchical_taxonomy( $post_type, $taxonomy_key, $name, $singular_name, $slug )
{
register_taxonomy(
$taxonomy_key,
$post_type,
array(
'label' => __( $singular_name ),
'labels' => array(
'name' => _x( $name, 'taxonomy general name' ),
'singular_name' => _x( $singular_name, 'taxonomy singular name' ),
'search_items' => __( 'Search '.$name ),
'popular_items' => __( 'Popular '.$name ),
'all_items' => __( 'All '.$name ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit '.$singular_name ),
'update_item' => __( 'Update '.$singular_name ),
'add_new_item' => __( 'Add New '.$singular_name ),
'new_item_name' => __( 'New '.$singular_name.' Name' ),
'menu_name' => __( $name ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'update_count_callback' => '',
'rewrite' => array(
'slug' => $slug,
'with_front' => false,
'hierarchical' => false,
),
'capabilities' => array('manage_terms', 'edit_terms', 'delete_terms', 'manage_categories', 'assign_terms',),
)
);
}
//Will create tag like taxonomy
function create_taxonomy( $post_type, $taxonomy_key, $name, $singular_name, $slug )
{
register_taxonomy(
$taxonomy_key,
$post_type,
array(
'label' => __( $singular_name ),
'labels' => array(
'name' => _x( $name, 'taxonomy general name' ),
'singular_name' => _x( $singular_name, 'taxonomy singular name' ),
'search_items' => __( 'Search '.$name ),
'popular_items' => __( 'Popular '.$name ),
'all_items' => __( 'All '.$name ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit '.$singular_name ),
'update_item' => __( 'Update '.$singular_name ),
'add_new_item' => __( 'Add New '.$singular_name ),
'new_item_name' => __( 'New '.$singular_name.' Name' ),
'separate_items_with_commas' => __( 'Separate '.$name.' with commas' ),
'add_or_remove_items' => __( 'Add or remove '.$name ),
'choose_from_most_used' => __( 'Choose from the most used '.$name ),
'menu_name' => __( $name ),
),
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => false,
'update_count_callback' => '',
'rewrite' => array(
'slug' => $slug,
'with_front' => false,
'hierarchical' => false,
),
'capabilities' => array('manage_terms', 'edit_terms', 'delete_terms', 'manage_categories', 'assign_terms',),
)
);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment