With Slam’s kind tip to use query-monitor plugin, I could figure out what the problem was.
Apparently the url /search/foo/filter/bar
also fits the “general search” rewrite-rule. Makes sense, thinking about it– (.+)
technically matches /foo/filter/bar
aswell. So I could improve (.+)
by excluding /
s?
But I found an easier solution!
In hope “first match wins” I declared the more specific rule before the general rule– and e voila, it worked!
add_filter("rewrite_rules_array", function($rules) {
$newRules = array();
// more specific rule first
$newRules["search/(.*)/filter/(.*)/?$"] = 'index.php?s=$matches[1]&filter=$matches[2]';
// general rule later
$newRules["search/(.+)/?$"] = 'index.php?s=$matches[1]';
$merged = array_merge($newRules, $rules);
return $merged;
});
Related Posts:
- How to add a Rewrite Rule / Category Structure
- Change the permalink URL to include a taxonomy term
- How to Rewrite Taxonomy URL to Include the Post Type as the Second Segment of the URL?
- Add Taxonomy Subcategory To Permalink
- Custom URLs in Custom Search Results
- Rewrite Search URL Permalink For CPT Custom Taxonomies
- Custom taxonomy still using query URL after fixing error
- custom taxonomy and pages rewrite slug conflict gives 404
- Remove taxonomy base or term from url
- Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
- Exclude Specific Term from Search
- WordPress database error: [Not unique table/alias: ‘wp_postmeta’]
- Custom slug in front of search URL
- WordPress Search – display taxonomy terms in results
- Removing taxonomy base using WP rewrite
- Query two taxonomies via URL or link?
- Custom taxonomy on permalink
- Custom taxonomies, with custom rewrites/slug, AND loading a taxonomy archive template from a plugin
- How to find taxonomy name using only taxonomy TERM ID (or taxonomy term name)
- URL rewrite rules for multiple taxonomies query
- Rewrite rule for custom taxonomy
- Nice URLs for a Custom Post Type List with a Shared Custom Taxonomy?
- Sort posts by number of matched terms
- How do I rewrite a url to use %taxonomy% instead of %category% when multiple taxonomies are present?
- Pros and cons of using [taxonomy name] in place of [category name]?
- WP redirects pretty permalink to query string
- Removing the base “Author” or changing it to something else. is it possible?
- Permalinks for quote authors
- Sorting Posts Via Custom Taxonomy Values Using Checkboxes?
- Change URL structure of subcategory archive pages
- add_rewrite_rule not working for language specific characters
- How to add custom taxonomy to search
- Add parent/child taxonomy to custom post type url
- Taxonomy.php issue with search and filters
- Extending wordpress search to include excerpts and taxonomies?
- How to filter WordPress search, excluding post in some custom taxonomies?
- how to search in custom fields & custom taxonomy for custom search
- Keep taxonomy base name in post permalinks
- Search by type posts and taxonomy
- custom taxonomy and custom post type url conflict
- How to create custom taxonomy URLs without taxonomy name?
- How to obtain the link/URL to the feed of a custom taxonomy?
- Permalinks for custom taxonomy stopped to work
- Taxonomy with_front causes all
- 404 error- issues with pages after adding custom rules for posts
- How to overwrite registered taxonomy url from vendor plugin in child theme
- How Can I Change a Taxonomy URL Based On The Originating URL?
- Creating a custom search form
- Get posts from taxonomy URL
- How to implement custom search with input fields?
- Rewrite URL for taxonomy listing
- Custom Post Types, URL rewrite on multiple CPTs
- How do I keep the page I’m on within the URL when running a search on a taxonomy?
- Add multiple taxonomy filters to edit.php that support search
- Get Taxonomy Term Title by it’s URL
- Custom permalinks with hierarchical taxonomy – getting PHP warning
- Rewrite Rule Working for all but one of the taxonomies created
- Page and Post return 404 with custom taxonomy
- Extend & Search Native WordPress Image Galleries With Tags and Taxonomies?
- Taxonomy Pagination Rewrite
- Custom Taxonomy Not Working When added to WordPress Search
- woocommerce custom product category template
- Search Tool only refreshes Page without showing results
- WordPress thinks my custom taxonomy pages are search pages #seo
- how to change permalinks format for pagination?
- Custom Taxonomy and Rewrite URL
- How do I create a permalink structure with 2 taxonomies
- Changing URLs for taxonomies and CPT
- Removing “s” from search with custom parameters
- Rewrite Rules returning wrong data
- Adding custom taxonomy in my existing category URL
- Taxonomy in URL
- Using custom taxonomies to display hierarchical URLs?
- Passing form inputs into multi-taxonomy query
- Pagination on Custom Tax Pages Removes Spaces from Query Vars
- How to rename custom taxonomy URL with extra words
- How to change url for taxonomy pages?
- Search Query for Multiple Terms In Same Taxonomy
- Query custom taxonomy by term id?
- Use an HTML Element To Filter Taxonomies In WP Search
- Custom Taxonomy specific to a Custom Post type – rewrite URL
- How to customize custom taxonomy url?
- Permalink Problems
- Why isn’t the ‘no results’ being shown when a query returns no results?
- How to add hierarchical taxonomy with parent child relation to URL?
- How best to store data (URLs and IDs) extracted from posts and pages using custom taxonomies
- Advanced search redirecting to another page then filter further
- Search only custom taxonomies
- pagination not working on custom-taxonomy template
- Custom rewrite permalink doesn’t work
- forward/redirect taxonomy archive of term to a page with same name
- URL rewriting taxonomy term
- WordPress autocomplete search with taxonomies
- Double slash in the_terms URL
- Geographic search with taxonomy structure [duplicate]
- How can i fix a 404 error when targeting custom taxonomy slug ?
- Custom Post Type URL Rewrite’s
- Permalink issues with custom taxonomies
- search using multiple taxonomies and keyword
- Taxonomy or Custom Field