Skip to content

Allow customization of facet widget query parameters #1198

Closed
@ray-lee

Description

Have you searched for similar issues before submitting this one?
Yes

Is this a bug, question or feature request?
Feature

Describe the issue you encountered:
Our search result page has links that allow users to change the sort order, and to limit the results to a single post type. These links go to URLs with query parameters like ?post_type=page&orderby=date&s=hello. When we add the facet widget, the terms in the widget are linked to URLs with query parameters like ?s=hello&filter_foo=bar. The post_type and orderby params are not retained, so the post type limitation and sort order are lost when the user clicks on a facet term. We want these to be maintained.

I would propose adding a filter that could be applied here:

function ep_facets_build_query_url( $filters ) {
$query_string = '';
$s = get_search_query();
if ( ! empty( $s ) ) {
$query_string .= 's=' . $s;
}
if ( ! empty( $filters['taxonomies'] ) ) {
$tax_filters = $filters['taxonomies'];
foreach ( $tax_filters as $taxonomy => $filter ) {
if ( ! empty( $filter['terms'] ) ) {
if ( ! empty( $query_string ) ) {
$query_string .= '&';
}
$query_string .= 'filter_' . $taxonomy . '=' . implode( array_keys( $filter['terms'] ), ',' );
}
}
}
return strtok( $_SERVER['REQUEST_URI'], '?' ) . ( ( ! empty( $query_string ) ) ? '?' . $query_string : '' );
}

So at line 451, something like:

$query_string = apply_filters( 'ep_facet_query_string', $query_string );

Happy to make a pull request for this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions