Taxonomy Widget
Current Category - Multiple Taxonomies - Enhancement (2 posts)

  1. bigevilbrain
    Posted 5 years ago #

    Relates to this widget: http://wordpress.org/tags/taxonomy-widget

    So, I'm using multiple custom taxonomies (kind of like a search refinement.)


    get_queried_object() and wp_list_categories() was only show the "first" taxonomy as the selected one (which adds 'current-cat' to the class.)

    Around line 190

    $taxonomy = $this->sanitize_taxonomy( $instance['taxonomy'] );
    // Multiple Taxonomies
    if (get_query_var($taxonomy)) {
    	// 'slug', 'name', or 'id'
    	$queried_object = get_term_by('slug', get_query_var($taxonomy), $taxonomy);

    Around line 250 (in the 'default' case)

    $taxonomy_args['hide_empty'] = false; // If you want all tags to appear...
    if( isset( $queried_object->taxonomy ) ) {
    	$taxonomy_args['current_category'] = $queried_object->term_id;
    wp_list_categories( apply_filters( 'mfields_taxonomy_widget_args_list', $taxonomy_args ) );

    This only works with 1 selection per taxonomy.

    Technically you can also do this... which will return 'loop-berber' AND 'pattern'. WordPress will return the correct results but only 1 of those tags will be highlighted.

    Send me an email if you want the full code.

    You can also do this... returns 'loop-berber' OR 'pattern'

  2. Michael Fields
    Plugin Author

    Posted 5 years ago #

    Feel free to send me the code for this. I would love to check it out! Haven't had the time to dive into such queries, but it's really good to know how multiple term queries can be modified via url ... I just updated this plugin and was wondering if that was possible.

    This plugin is developed on Github https://github.com/mfields/taxonomy-widget if it's easier to send a pull request.


Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Taxonomy Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic