WordPress.org

Ready to get started?Download WordPress

Forums

Make Existing Flat Taxonomy Hierarchical (2 posts)

  1. Goose
    Member
    Posted 3 years ago #

    We have an existing taxonomy that was created using Yoast's Simple Taxonomy plug-in a year or so ago. Now we'd like to turn this taxonomy into a hierarchical taxonomy - we've tried some of the newer taxonomy plug-ins but they do not recognize the existing taxonomy (or the other older taxonomies we have) that were registered using the Yoast plug-in.

    We are able to create a new hierarchical taxonomy without a problem now in 3.01 using these newer plug-ins (and it shows up next to the other older taxonomies). Any ideas on how to convert our older taxonomy into a hierarchical taxonomy would be appreciated.

  2. MichaelH
    Member
    Posted 3 years ago #

    I installed Simple Taxonomy, created a new taxonomy called SimpleTax, created one term under that 'non-hierarchical' taxonomy, then wrote a post and attached that term to the post.

    Then putting this in my theme's functions.php sets the taxonomy to hierarchical:

    function pfx_create_taxonomies()
    {
      // Add new taxonomy, make it hierarchical (like categories)
      $labels = array(
        'name' => _x( 'SimpleTax', 'taxonomy general name' ),
        'singular_name' => _x( 'SimpleTax', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search SimpleTaxs' ),
        'popular_items' => __( 'Popular SimpleTaxs' ),
        'all_items' => __( 'All SimpleTaxs' ),
        'parent_item' => __( 'Parent SimpleTax' ),
        'parent_item_colon' => __( 'Parent SimpleTax:' ),
        'edit_item' => __( 'Edit SimpleTax' ),
        'update_item' => __( 'Update SimpleTax' ),
        'add_new_item' => __( 'Add New SimpleTax' ),
        'new_item_name' => __( 'New SimpleTax Name' ),
      ); 	
    
      register_taxonomy('simpletax',array('post'), array(
        'hierarchical' => true,
        'labels' => $labels,
        'show_ui' => true,
        'query_var' => true,
        'rewrite' => array( 'slug' => 'simpletax', 'with_front' => true ),
      ));
    
    }
    add_action('init', 'pfx_create_taxonomies');

    And even with Simple Taxonomies activated, it looked to use the SimpleTax taxonomy as if it were hierarchical.

    If you choose to deactivate Simple Taxonomies you could define each of your taxonomies like the above but you would lose the extra features provided by that plugin.

Topic Closed

This topic has been closed to new replies.

About this Topic