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?
- Relative URLs and hide /wp-content/themes/
- 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 to customize search result page title?
- 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/?
- Php string not working in WordPress Functions.php (trying to fetch 1st category for each blog that post appears in the sidebar)
- Add class to Categories Widget
- How to Acheive the custom woocommerce category template
- custom naming of search permalink /search/
- Display WordPress Search
- 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
- Search user metadata with checkboxes via ajax (almost working)
- How to show in search results posts with a particular tag in a particular category?
- Programmatically Create Category and sub Category
- Searching for content post
- Attach parent category template to all subcategories
- How can I create a page with a specific URL?
- exclude a category from a search on a specific page
- 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
- Possible to display shortcode based on the category?
- Unset Category if other Category is unset during post transition
- Select pages by category
- 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
- allow only one post in specific category
- How to obtain the recent posts without their content in an efficient way?
- Setting a default text for excerpts of a particular category
- Running script based on 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?
- issue with if/elseif in_array inside foreach loop display only one post
- Randomizing wp_tag_cloud() in child theme
- add_filter to specific WooCommerce Category
- Image loading function not working on archive.php template
- 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
- Rewrite Question Mark in Post Template with URL Parameter for clean URLs
- search form leads to 404
- 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
- Get slug of current category in functions.php
- Create Custom URL structure for specific Post category using Post ID instead of post name
- WordPress: Highlight search result exact matches
- Display a list of random terms from custom taxonomy with shortcode
- Custom route and extract data from slashes and parameter
- Change category display name function
- reWrite wp-content url to point on my cdn
- Display link to category over featured image
- Add #primary at the end of navlink permalinks on single posts
- 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