Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facet by Meta Range block foundations #3289

Merged
merged 11 commits into from
Feb 1, 2023
Prev Previous commit
Next Next commit
Adjust selected filters
  • Loading branch information
felipeelia committed Feb 1, 2023
commit ee8a75836d7f0c15976a6ab419a8a4eec5e6e633
7 changes: 3 additions & 4 deletions includes/classes/Feature/Facets/FacetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ public function get_sanitize_callback() : string {
*/
public function format_selected( string $facet, $value, array $filters ) {
$terms = explode( ',', trim( $value, ',' ) );
return [
$facet => [
'terms' => array_fill_keys( array_map( $this->get_sanitize_callback(), $terms ), true ),
],
$filters[ $this->get_filter_type() ][ $facet ] = [
'terms' => array_fill_keys( array_map( $this->get_sanitize_callback(), $terms ), true ),
];
return $filters;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/Feature/Facets/Facets.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ public function get_selected() {
if ( 0 === strpos( $key, $filter_name ) ) {
$facet = str_replace( $filter_name, '', $key );

$filters[ $type_obj->get_filter_type() ] = $type_obj->format_selected( $facet, $value, $filters );
$filters = $type_obj->format_selected( $facet, $value, $filters );
}
}

Expand Down
12 changes: 6 additions & 6 deletions includes/classes/Feature/Facets/Types/MetaRange/FacetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,14 @@ public function set_wp_query_aggs( $facet_aggs ) {
* @return array
*/
public function format_selected( string $facet, $value, array $filters ) {
$filter_type = $this->get_filter_type();
$min_or_max = substr( $facet, -4 );
$field_name = substr( $facet, 0, -4 );
$return = $filters[ $filter_type ][ $field_name ] ?? [];
$min_or_max = substr( $facet, -4 );
$field_name = substr( $facet, 0, -4 );

$return[ $min_or_max ] = $value;
$filters[ $this->get_filter_type() ][ $field_name ] = [
$min_or_max => $value,
];

return [ $field_name => $return ];
return $filters;
}

/**
Expand Down