WordPress.org

Support

Support » Themes and Templates » Custom taxonomy “hierarchical’ => true” not working

Custom taxonomy “hierarchical’ => true” not working

  • 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!

Viewing 7 replies - 1 through 7 (of 7 total)
  • 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…

    “…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.

    Custom taxonomies in WordPress 2.8

    @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.

    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 😀

    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…

    pampfelimetten

    @pampfelimetten

    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

    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.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Custom taxonomy “hierarchical’ => true” not working’ is closed to new replies.
Skip to toolbar