Snippets

yourstyle Register Custom Taxonomy using WP TAXONOMY API

Created by Zsolt Revay - Giran
<?php

/**
* Register early so we can use get_object_taxonomies() at 8
* at vc_before_init hook otherwhise VC weill not see them
*/

add_action('init', 'register_taxonomy_employees_category',8);

add_action('init', 'register_taxonomy_employees_category',8);

function register_taxonomy_employees_category() {

    $taxonomy = 'employee_category';
    $rewrite  = 'employee_category';
    $p_type = array('employee');
    
    $single = __('Employee', 'ysd-inter-plugin');
    $multiple = __('Employees', 'ysd-inter-plugin');
    
    register_taxonomy( $taxonomy ,$p_type ,array (
        'hierarchical' => true,
        'label' => __("{$single} Categories", 'ysd-inter-plugin'),
        'show_ui' => true,
        'query_var' => true,
        'show_admin_column' => true,
        'rewrite' => array ( 'slug' => $rewrite ),
        'public' => false, // Disable If the taxonomy should be publicly queryable.
        'show_in_menu' => true, //Where to show the taxonomy in the admin menu. show_ui must be true.
        'show_in_rest' => true,
        'show_tagcloud' => false,
        'show_in_nav_menus' => false,
        'labels' => array (
          'search_items' => __("Search {$single} Categories", 'ysd-inter-plugin'),
          'popular_items' => __('Popular Categories', 'ysd-inter-plugin'),
          'all_items' => __("All {$multiple} Categories", 'ysd-inter-plugin'),
          'parent_item' => __("Parent {$multiple} Categories", 'ysd-inter-plugin'),
          'parent_item_colon' => '',
          'edit_item' => __('Edit', 'ysd-inter-plugin'),
          'update_item' => __('Update', 'ysd-inter-plugin'),
          'add_new_item' => __("Add new {$single} category", 'ysd-inter-plugin'),
          'new_item_name' => __("New {$single} category name", 'ysd-inter-plugin'),
          'separate_items_with_commas' => '',
          'add_or_remove_items' => '',
          'choose_from_most_used' => '',
        ),
        'show_in_graphql' => true,            // Use it in combination with GraphQL Plugin
        'graphql_single_name' => 'venue',     // Use it in combination with GraphQL Plugin
        'graphql_plural_name' => 'venues',    // Use it in combination with GraphQL Plugin
        ) 
    ); 
}

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.