Create custom taxonomy in wordpress


<?php
   
    // ******************************************************************************
    // *** REMEMBER TO PUT THIS CODE INSIDE 'functions.php' inside your themes folder.
    // ******************************************************************************
   
    $labels_categories = array(
        'name' => _x( 'Custom_Taxonomy', 'taxonomy general name' ),
        'singular_name' => _x( 'Custom_Taxonomy', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Custom_Taxonomys' ),
        'all_items' => __( 'All Custom_Taxonomy' ),
        'parent_item' => __( 'Parent Custom_Taxonomy' ),
        'parent_item_colon' => __( 'Parent Custom_Taxonomy:' ),
        'edit_item' => __( 'Edit Custom_Taxonomy' ),
        'update_item' => __( 'Update Custom_Taxonomy' ),
        'add_new_item' => __( 'Add New Custom_Taxonomy' ),
        'new_item_name' => __( 'New Custom_Taxonomy Name' ),
    );
    // 'Custom_Taxonomy' replace this with the name of your post type

    register_taxonomy(
        'custom-taxonomy', // The name of the custom taxonomy
        array( 'custom-taxonomy', 'custom-postType' ),
        // Replace 'custom-taxonomy' with yours. Be sure to choose this wisely as this becomes your url for the custom taxonomy
        // Associate it with any custom post type by giving their slug.
       
        array(
            'hierarchical' => true,
            'rewrite' => array(
                'slug' => 'custom-taxonomy', // Use "topic" instead of "topics" in permalinks
                'hierarchical' => true // Allows sub-topics to appear in permalinks
                ),
            'labels' => $labels_categories
            )
    );
       
    // -- ** END Custom_Taxonomy TAXONOMY ** -- //

?>

// ******************************************************************************
// *** REMEMBER TO PUT THIS CODE INSIDE ‘functions.php’ inside your themes folder.
// ******************************************************************************

Latest Comments

Leave a Reply

comment on this article