How to Create Custom Taxonomy in WordPress

How-to-Create-Custom-Taxonomy-in-Wordpress

This code used for Create Custom Taxonomy and this code add your function.php file WordPress.

Categories are one of the built-in taxonomies in WordPress, but they only appear in custom posts by default.

We’ll show you how to add categories to a custom post type in WordPress.

<?php
function add_console_taxonomies() {

 register_taxonomy('console', 'test', array(
  // Hierarchical taxonomy (like categories)
  'hierarchical' => true,
  // This array of options controls the labels displayed in the WordPress Admin UI
  'labels' => array(
   'name' => _x( 'Sale Listings Category', 'taxonomy general name' ),
   'singular_name' => _x( 'Sale-Listings-Category', 'taxonomy singular name' ),
   'search_items' =>  __( 'Search Sale-Listings-Category' ),
   'all_items' => __( 'All Sale-Listings-Category' ),
   'parent_item' => __( 'Parent Sale-Listings-Category' ),
   'parent_item_colon' => __( 'Parent Sale-Listings-Category:' ),
   'edit_item' => __( 'Edit Sale-Listings-Category' ),
   'update_item' => __( 'Update Sale-Listings-Category' ),
   'add_new_item' => __( 'Add New Sale-Listings-Category' ),
   'new_item_name' => __( 'New Sale-Listings-Category Name' ),
   'menu_name' => __( 'Sale Listings Categories' ),
  ),

  // Control the slugs used for this taxonomy
  'rewrite' => array(
   'slug' => 'test', // This controls the base slug that will display before each term
   'with_front' => false, // Don't display the category base before "/locations/"
   'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
  ),
 ));
}

add_action( 'init', 'add_console_taxonomies', 0 );

?>
Learn Tutorials Point
We Well organized and easy-to-understand Interactive tutorials With lots of examples of how to use Tutorials WordPress, PHP, Bootstrap, Bootstrap 4, HTML, CSS, AJAX, jQuery, Woocommerce, Post, Database, Javascript, Theme, Responsive, Templates.

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact us

Fill in the form below or give us a call and we'll contact you. We endeavour to answer all enquiries within 24 hours on business days.