Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## [Unreleased]

## v2.3.1 - 2024.08.19

### Fixed

- Fix facets applying on non-main queries ([#49](https://github.com/studiometa/wp-toolkit/issues/49), [#50](https://github.com/studiometa/wp-toolkit/pull/50), [9c098c7](https://github.com/studiometa/wp-toolkit/commit/9c098c7))

### Added

- Add a CLAUDE.md file ([c28b253](https://github.com/studiometa/wp-toolkit/commit/c28b253))

## v2.3.0 - 2024.08.14

### Added

- Add support for custom taxonomies filtering ([#42](https://github.com/studiometa/wp-toolkit/issues/42), [#43](https://github.com/studiometa/wp-toolkit/pull/43), [ae541b5](https://github.com/studiometa/wp-toolkit/commit/ae541b5))
Expand Down
14 changes: 14 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# WordPress Toolkit by Studio Meta

## Development commands

- `ddev start` to start the DDEV project where the PHPUnit tests will be run
- `ddev exec composer test` to run the PHPUnit tests
- `composer lint:style` to check for code quality with PHPCS
- `composer fix:style` to fix fixable errors reported by PHPCS
- `composer lint:static` to do static analysis with PHPStan

## Guidelines

- Follow existing patterns
- Follow modern PHP features and standard
2 changes: 1 addition & 1 deletion src/Managers/FacetsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function run()
*/
public function add_facets_to_query(WP_Query &$query): void
{
if (!is_array($this->facets)) {
if (!is_array($this->facets) || !$query->is_main_query()) {
return;
}

Expand Down
17 changes: 17 additions & 0 deletions tests/Managers/FacetsManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,21 @@ public function test_it_should_handle_array_values_in_facets()
$this->assertEquals(['slug1', 'slug2'], $tax_query[0]['terms']);
$this->assertEquals('slug', $tax_query[0]['field']);
}

public function test_it_should_not_add_facets_to_non_main_query()
{
request()->query->set('facets', ['cat' => 1]);
$manager = new FacetsManager();
$manager->run();

// Create a non-main query
$secondary_query = new WP_Query();
$secondary_query->init();

// Manually call the method to simulate what happens on pre_get_posts
$manager->add_facets_to_query($secondary_query);

// The facets should not be applied to the secondary query
$this->assertFalse(isset($secondary_query->query_vars['cat']));
}
}
Loading