Skip to content

Preserve filters when searching on events page#1674

Open
dd32 wants to merge 1 commit intoWordPress:productionfrom
dd32:fix/claude/1167-search-preserves-filters
Open

Preserve filters when searching on events page#1674
dd32 wants to merge 1 commit intoWordPress:productionfrom
dd32:fix/claude/1167-search-preserves-filters

Conversation

@dd32
Copy link
Copy Markdown
Member

@dd32 dd32 commented Mar 24, 2026

Summary

  • The search block on the events page submitted to the default WordPress search results URL, losing any active filters and leaving the events page
  • Fixes this by using the render_block_core/search filter to change the search form action URL and inject active filter values as hidden inputs
  • Includes integration tests for the new functionality

Test plan

  • Go to the events page and apply a filter (e.g. Format: Online)
  • Enter a search term and submit
  • Verify the search results still show on the events page (not the WordPress search results page)
  • Verify the filter is still active after searching
  • Search without any filters active - verify it still works and stays on the events page

Fixes #1167

Generated with Claude Code

@dd32 dd32 added [Component] Events Widget Related to the core dashboard upcoming events widget, syncing process, or Official WP Events plugin [Type] Bug labels Mar 24, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dd32 dd32 force-pushed the fix/claude/1167-search-preserves-filters branch from cf6bf2b to dabb3c8 Compare April 29, 2026 06:27
Copilot AI review requested due to automatic review settings April 29, 2026 06:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the wporg-events-2023 theme so that submitting the Search block on event listing pages keeps users on the events page and preserves any active event filters by modifying the rendered search form output.

Changes:

  • Hook into render_block_core/search to rewrite the search form action URL and inject active filter values as hidden inputs.
  • Add a new PHPUnit test suite and theme-specific test bootstrap for the events theme.
  • Add integration tests covering hidden input injection and basic action URL rewriting behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
public_html/wp-content/themes/wporg-events-2023/inc/events-query.php Adds a render filter for the Search block and implements hidden filter injection + form action rewriting.
public_html/wp-content/themes/wporg-events-2023/tests/test-events-query.php Adds tests for the new search-form modification behavior.
public_html/wp-content/themes/wporg-events-2023/tests/bootstrap.php Adds a theme test bootstrap to load the required theme code for tests.
phpunit.xml.dist Registers a new PHPUnit testsuite for the events theme tests.
phpunit-bootstrap.php Loads the events theme test bootstrap in the global PHPUnit bootstrap sequence.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +363 to +370
// Update the form action to stay on the events page rather than going to
// the default WordPress search results page.
$action_url = build_form_action_url();
$block_content = preg_replace(
'/action="[^"]*"/',
'action="' . esc_url( $action_url ) . '"',
$block_content
);
Comment on lines +120 to +123
// The action should no longer be the original example.org URL.
$this->assertStringNotContainsString( 'action="http://example.org/"', $result );
// It should contain an action attribute with a URL pointing to the post.
$this->assertMatchesRegularExpression( '/action="https?:\/\/[^"]+?"/', $result );
Comment on lines +9 to +62
/**
* @group wporg-events-2023
*
* @coversDefaultClass \WordPressdotorg\Events_2023
*/
class Test_Events_Query extends WP_UnitTestCase {

/**
* Sample search form HTML to use in tests.
*
* @var string
*/
private $sample_form = '<form role="search" method="get" action="http://example.org/" class="wp-block-search__button-outside"><label class="wp-block-search__label" for="wp-block-search__input-1">Search</label><div class="wp-block-search__inside-wrapper"><input class="wp-block-search__input" id="wp-block-search__input-1" placeholder="" value="" name="s" /><button aria-label="Search" class="wp-block-search__button" type="submit">Search</button></div></form>';

/**
* Clean up query vars after each test.
*/
public function tear_down(): void {
global $wp_query;

set_query_var( 'event_type', '' );
set_query_var( 'format_type', '' );
set_query_var( 'month', '' );
set_query_var( 'country', '' );

parent::tear_down();
}

/**
* Test that hidden inputs are injected when active filters exist.
*
* @covers ::inject_filters_into_search_form
*/
public function test_injects_hidden_inputs_for_active_filters(): void {
set_query_var( 'event_type', array( 'meetup' ) );
set_query_var( 'country', array( 'US' ) );

$result = \WordPressdotorg\Events_2023\inject_filters_into_search_form( $this->sample_form );

$this->assertStringContainsString(
'<input type="hidden" name="event_type[]" value="meetup" />',
$result
);
$this->assertStringContainsString(
'<input type="hidden" name="country[]" value="US" />',
$result
);
}

/**
* Test that multiple values for a single filter produce multiple hidden inputs.
*
* @covers ::inject_filters_into_search_form
*/
Comment thread phpunit-bootstrap.php
require_once WP_PLUGIN_DIR . '/wordcamp-payments-network/tests/bootstrap.php';
require_once SUT_WPMU_PLUGIN_DIR . '/tests/bootstrap.php';
require_once WP_PLUGIN_DIR . '/wordcamp-coming-soon-page/tests/bootstrap.php';
require_once SUT_WP_CONTENT_DIR . '/themes/wporg-events-2023/tests/bootstrap.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Component] Events Widget Related to the core dashboard upcoming events widget, syncing process, or Official WP Events plugin [Type] Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Events: Searching removes existing filters.

2 participants