WordPress.org

Support

Support » Plugins and Hacks » Current Category – Multiple Taxonomies – Enhancement

Current Category – Multiple Taxonomies – Enhancement

  • bigevilbrain
    Member

    @bigevilbrain

    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

Viewing 1 replies (of 1 total)
  • Plugin Author Michael Fields
    Member

    @mfields

    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

Viewing 1 replies (of 1 total)
  • The topic ‘Current Category – Multiple Taxonomies – Enhancement’ is closed to new replies.