WordPress.org

Ready to get started?Download WordPress

Forums

Custom taxonomy "hierarchical' => true" not working (8 posts)

  1. LJK
    Member
    Posted 5 years ago #

    I've been trying to set up two custom taxonomies in 2.8 for "Course subject" and "Type of opportunity".

    I used this code in functions.php:

    function create_pc_db_taxonomies() { register_taxonomy( 'course', 'post', array( 'hierarchical' => false, 'label' => __('Course subject', 'series'), 'query_var' => 'course', 'rewrite' => array( 'slug' => 'courses' ) ) ); register_taxonomy( 'type', 'post', array( 'hierarchical' => false, 'label' => __('Type of opportunity', 'series'), 'query_var' => 'type', 'rewrite' => array( 'slug' => 'types' ) ) ); } ?>

    which works absolutely fine, but I want hierarchical (category-style) admin boxes rather than tag-style admin boxes.

    However, when I set hierarchical' => true so that the above code becomes:

    function create_pc_db_taxonomies() { register_taxonomy( 'course', 'post', array( 'hierarchical' => true, 'label' => __('Course subject', 'series'), 'query_var' => 'course', 'rewrite' => array( 'slug' => 'courses' ) ) ); register_taxonomy( 'type', 'post', array( 'hierarchical' => true, 'label' => __('Type of opportunity', 'series'), 'query_var' => 'type', 'rewrite' => array( 'slug' => 'types' ) ) ); } ?>

    I get no boxes at all.

    Am I doing something wrong? Thanks!

  2. Alex Cragg
    Member
    Posted 5 years ago #

    I'm also trying to do this, so bumping it up.

    It seems strange that in taxonomy.php, category is defined using hierarchical => true.

    And there is no unregister_taxonomy, to try removing category and adding another one in its place, and I want category to be there still anyway...

  3. Aldi
    Member
    Posted 4 years ago #

    "...hierarchical custom taxonomies have been working since WordPress 2.3. It’s not working in the sense that WordPress will automatically add meta boxes and admin menus for you."

    I read somewhere that, currently, you have to create the widget (meta boxes, etc.) yourself.

    http://justintadlock.com/archives/2009/05/06/custom-taxonomies-in-wordpress-28#comment-127816

  4. Alex Cragg
    Member
    Posted 4 years ago #

    @bedex78 - Yeah I read that too. It just seemed like too much work for something that was just me playing around!

    Hopefully coming releases will automate it.

  5. Joel
    Member
    Posted 4 years ago #

    Looking forward to this too.

    After setting the 'hierarchical = TRUE' argument in the register_taxonomy $args parameter, not sure I understand how to identify the label as a child or parent of a different label (a pseudo category taxonomy).

    Would this be achieved by appropriately setting the 'query_var' argument within the $args parameter?

    For instance, take the first post as an example, what would you replace the "???" with below if you wanted to create the 'course' taxonomy as a child of the 'type' taxonomy:

    function create_pc_db_taxonomies() { register_taxonomy( 'course', 'post', array( 'hierarchical' => false, 'label' => __('Course subject', 'series'), 'query_var' => '???', 'rewrite' => array( 'slug' => 'courses' ) ) );

    register_taxonomy( 'type', 'post', array( 'hierarchical' => false, 'label' => __('Type of opportunity', 'series'), 'query_var' => '???', 'rewrite' => array( 'slug' => 'types' ) ) ); } ?>

    Or maybe I'm way off...thanks in advance for any help :D

  6. Aldi
    Member
    Posted 4 years ago #

    Not sure if any of you had found this plug-in, but I thought it is currently a good work around for creating hierarchical custom taxonomies.

    http://nerdlife.net/custom-taxonomies/

    Hopefully, the author will keep updating it, though...

  7. pampfelimetten
    Member
    Posted 4 years ago #

    http://core.trac.wordpress.org/ticket/10122

    Theres a patch - the ticket needs testing, so go for it, maybe we can bring it into 2.9

  8. jevets
    Member
    Posted 4 years ago #

    I was trying to get hierarchical working, but yoast's plugin removed my need to continue coding it.

    http://yoast.com/wordpress/simple-taxonomies/

    This plugin supports non-multiple selection of terms, which in my case is important. I'm using a taxonomy to section out the site, where a post can belong to only one section. It's hierarchical, too, which is also very good for my application.

Topic Closed

This topic has been closed to new replies.

About this Topic