WordPress.org

Ready to get started?Download WordPress

Forums

Query Multiple Taxonomies
[resolved] Hierarchical Taxonomies and Categories (9 posts)

  1. Phlux0r
    Member
    Posted 3 years ago #

    Hey scribu

    thanks for all the good work on this extremely useful plugin. I do have a question though.

    I have a custom hierarchical Make/Model taxonomy where the first level (parent) is a make (ie. Canon, HTC, etc...) and the second level (children) are the models the make has. This is tied into the categories which are the type of product (ie. Digital Cameras, Mobile Phones, etc...) and are also hierarchical.

    What I want is to be able to display the filtering widget with drop-downs populated in a tree-like hierarchical structure as opposed to the current one-level view. I know WordPress does this so I was wondering if there is a way to add this to the widget. I don't mind coding it myself if you give me some pointers.

    I identified that the work is done in: qmt_get_terms() which either calls: QMT_Terms::get( $tax ) or get_terms( $tax ) but how to get the 'nested' terms from there?

    TIA, Robert

    http://wordpress.org/extend/plugins/query-multiple-taxonomies/

  2. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Well, you would need to use the Walker_CategoryDropdown class defined in wp-includes/classes.php.

    See query-multiple-taxonomies/widget.php

  3. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    I landed this in the development version (1.3.1-alpha2).

  4. Phlux0r
    Member
    Posted 3 years ago #

    Thanks for addressing this so quickly. Shows up quite nicely however it uses IDs to pass to the query string instead of the category and taxonomy slugs so there are no results... is this due to the change you made?

    I Haven't had a good look at the code yet...

  5. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Ah... forgot about that. I'll take another look.

  6. Phlux0r
    Member
    Posted 3 years ago #

    Having had a look, you need to override Walker_CategoryDropdown and implement your own start_el() method since the original hard-codes using the term id.

    Then you can do:
    $walker = new QMT_Category_Walker();
    and pass your walker to the dropdown function:
    ...

    walk_category_dropdown_tree( $terms, 0, array(
        'selected' => qmt_get_query( $taxonomy ),
        'show_count' => true,
        'show_last_update' => false,
        'hierarchical' => true,
        'walker' => $walker,
    ) )
  7. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    Yep, that's just what I did. See the development version (1.3.1-alpha3).

    Maybe I should let you write the next version. :P

  8. Phlux0r
    Member
    Posted 3 years ago #

    Hm, I will probably make some mods to the widget code to customize it to the needs of my current project.

    As it stands, there is a lot of 'presentation' stuff in the code so it's not easy to customize it without touching the core plugin. Maybe you can look at providing some filter hooks for certain areas...

    If I end up with some mods that could be useful to others, I can pass the code onto you to include in your plugin if you want.

  9. scribu
    Member
    Plugin Author

    Posted 3 years ago #

    It already has several filters, but patches are always welcome.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic