How to create custom taxonomy in wordpress

Creating Custom taxonomy guide


There are two options available for creating custom taxonomies in Wordpress. First one is creating via plugins and another one is creating a taxonomy via your templates. Most used and useful ways create via your template. GOTO Wordpress template folder and open active template functions.php file

add_action is used to create your hook file for the new post type and taxonomy in Wordpress
Add the add_action in your functions.php file. Example: add_action( 'init', 'career_category', 0 );

Create the function for adding your taxonomy details

function career_category(){


}

Add your relevant labels in your function

$labels = array(

    'name' => _x( 'Category', 'taxonomy general name' ),

    'singular_name' => _x( 'Category', 'taxonomy singular name' ),

    'search_items' =>  __( 'Search Category' ),

    'all_items' => __( 'All Category' ),

    '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' => __( 'Category' ),

  );

Add your taxonomy register information. Careers your new taxonomy and career is your post type. Final Code is

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

function career_category() {

  $labels = array(

    'name' => _x( 'Category', 'taxonomy general name' ),

    'singular_name' => _x( 'Category', 'taxonomy singular name' ),

    'search_items' =>  __( 'Search Category' ),

    'all_items' => __( 'All Category' ),

    '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' => __( 'Category' ),

  );

 register_taxonomy('careers',array('career'), array(

    'hierarchical' => true,

    'labels' => $labels,

    'show_ui' => true,

    'show_admin_column' => true,

    'query_var' => true,

    'rewrite' => array( 'slug' => 'careers' ),

  ));



}

Related Post


Latest Post


Recent Posts Widget

Make sure to never miss a thing...

Get the latest news from the creative industry along with other creative goodies, conveniently delivered to social media.