WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. bigevilbrain
    Member
    Posted 3 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.)

    http://example.com/?carpet-type=loop-berber&carpet-manufacturer=beaulieu&carpet-color-family=blues

    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.
    http://example.com/?carpet-type=loop-berber+pattern

    Send me an email if you want the full code.

    You can also do this... returns 'loop-berber' OR 'pattern'
    http://example.com/?carpet-type=loop-berber,pattern

  2. Michael Fields
    Themer
    Plugin Author

    Posted 3 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.

    Best,
    -Mike

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic