You can use add_rewrite_rule()
:
add_action( 'init', function(){
// Non-paged requests. E.g. example.com/categoryname/search/keyword/
add_rewrite_rule( '^categoryname/search/([^/]+)/?$',
'index.php?category=categoryname&s=$matches[1]',
'top' );
// For paged requests. E.g. example.com/categoryname/search/keyword/page/2/
add_rewrite_rule( '^categoryname/search/([^/]+)/page/(\d+)/?$',
'index.php?category=categoryname&s=$matches[1]&paged=$matches[2]',
'top' );
} );
Be sure to flush the permalinks — simply visit the Permalink Settings page.
Related Posts:
- Using wp_redirect and .htaccess to re-route searches (and pass along the remaining GET vars)
- WordPress is adding pagination for all pages not only for blog page, How to remove pagination for all pages except blog/posts page?
- Display random categories on the front page (Finding and Editing Theme Functions)
- How to redirect to post if search results only returns one post
- Use author author display name in permalink structure for pages and posts
- Possible to search by author name with default WordPress search function?
- paginate_links() don’t properly work in search.php?
- Filter the query ONLY for the search results page
- How to add classes to images based on their categories?
- Extending the site search to include a single custom field
- current_cat_ancestor Alternatives
- Modify search function in WordPress (TwentyTwelve)
- Add body class of category parent
- How do you permanently remove default rewrite rules from the wp_options table?
- Changing a function in function.php to a shortcode – for listing categories of only a certain post type
- How to add .htaccess code through a function?
- How to? Redirect /category/sci-fi/ to /category/scifi/?
- How to Acheive the custom woocommerce category template
- How to add a rel attribute to images that contains their categories?
- How to set child post categories to parent post categories when updating parent post?
- Assign category using custom field?
- How To Get WordPress Categories Link List?
- Changing post category from dropdown
- Manipulate Output of wp_list_something: select menu instead of li’s
- WordPress Content Security Policy and Subresource Integrity
- Make Categories a Dropdown Menu in Media Library
- Programmatically Create Category and sub Category
- Searching for content post
- How can I create a page with a specific URL?
- Get the category name outside of the loop in category.php
- Is it possible to change any of the HTML/URL returned from the_category()
- Custom HTML in specific category single page and its descendant categories
- How do I redirect all 404 error url to Subcategory url
- Unset Category if other Category is unset during post transition
- changing behaviour of get_search_form
- How to rewrite the custom url in wordpress?
- Show Primary Category first when I display post categories
- How do I hide or remove ‘Category’ from wordpress breadcrumbs
- Ordering posts by publish date not working?
- Search filter by Post title OR Meta Title Value [duplicate]
- Categories as main menu items and subcategories as nested lists
- meta tags doesnt fetch data from permalinks
- paginate_links() don’t properly work in search.php?
- Remove category from url
- Redirect to another page using contact form 7? [closed]
- Get category URL for current post
- Need help “sanitizing” a custom function that pulls category slug into body class
- How to obtain the recent posts without their content in an efficient way?
- Setting a default text for excerpts of a particular category
- Remove a category from a post when saving a new post
- How to fix get_the_category function returning incorrect slug?
- Return category name with & Ampersand doesnt work
- Include the post type before the title of search results
- Page get parameter doesn’t work with is_single() function
- Access category within rss2_head hook?
- add_filter to specific WooCommerce Category
- Exclude Category ID in function
- Problem with calling custom function in a foreach loop
- How to Add Shortcode to html img code?
- Specify multiple categories for custom post template – FATAL ERROR
- “All posts” in the category widget
- Get Attachment Category Name
- two search forms on the same page
- Internet Explorer opens links to .msi files as text in a new tab
- Custom function for search form
- Custom url structure – pages under a custom post type
- WordPress Categories: Function using custom SQL to return array of specific category IDs
- Display ACF category image on archive and single template files
- Create Custom URL structure for specific Post category using Post ID instead of post name
- WordPress: Highlight search result exact matches
- Custom route and extract data from slashes and parameter
- Change category display name function
- Display link to category over featured image
- Remove the ‘category’ url for one category type
- Custom Function.PHP Code Not Working on One Site
- Adding new Category does not refresh the backoffice
- How do i tweak my wp Post title base on category of the post
- Limiting WordPress Search function : Custom build
- how to remove a tag in the_category function
- Menu and category highlighting for a single post
- i can’t use wordpress functions in ajax loaded php file
- Route wordpress with template
- More than one search results page template for two searches on site
- How do i create a search option for pdf’s only
- Graphic before title – Specific Category
- require_once() Causing categories and tag pages on dashboard to not refrsh
- Rewrite rules and the permalink
- Edit meta fields from within template
- different body classes for each category
- WordPress Category url redirects to subdomain
- Limit Number of Posts on Blog Category Page Throwing 404 Error on Paginated Pages
- Problem with add_rewrite_tag
- How To Get WordPress Categories Last Update Date?
- How to add a meta information to the URL?
- Make WordPress search for only this tags or exclude certain tags from search [duplicate]
- How to get tags and categories?
- child_of not working while searching
- How to Insert A List of Posts in A Category Written by the Author into the Author Archive
- Custom Post Type Search
- Get category of post inside save_post hook