My sincere apologies for asking this question as I am quite certain that this is a relatively easy topic, unfortunately my many hours of searching got me no satisfying results. I do not mind researching this further so any links to relevant posts are much appreciated!
The problem
I want my users to land on a specific archive page after using the search form on my home page. Example; when the user uses the search form on mysite they are redirected to all results in the archive of a specific custom post type; mysite/customposttype/?s=search-therm
I am using Elementor Pro to style the search form and would therefore like to keep this functionality.
Attempts
I built a new search form with a hidden input with the name of my custom post type. This unfortunately still lead to the standard archive (mysite/?s=search-term) and not the custom post type archive.
How can I adapt the search form in such a way that I can have multiple search forms on my website that all redirect to a specific custom post type directory?
Thanks!
My sincere apologies for asking this question as I am quite certain that this is a relatively easy topic, unfortunately my many hours of searching got me no satisfying results. I do not mind researching this further so any links to relevant posts are much appreciated!
The problem
I want my users to land on a specific archive page after using the search form on my home page. Example; when the user uses the search form on mysite.com they are redirected to all results in the archive of a specific custom post type; mysite.com/customposttype/?s=search-therm
I am using Elementor Pro to style the search form and would therefore like to keep this functionality.
Attempts
I built a new search form with a hidden input with the name of my custom post type. This unfortunately still lead to the standard archive (mysite.com/?s=search-term) and not the custom post type archive.
How can I adapt the search form in such a way that I can have multiple search forms on my website that all redirect to a specific custom post type directory?
Thanks!
Simply make an HTML form in Elementor on the archive page where you want to search.
Code:
<form class="zohaib-search-form" role="search" action="/courses" method="get">
<input placeholder="Search.." name="s" type="search">
<button type="submit"><i class="fas fa-search"></i></button>
**Note:** name property of input should be 's' because the search query is looking for key 's' to get and run it.
Replace the action property with your custom post type. It will only work if the action link will be an archive page. After submit the search the filter result will also show on the same archive page like mine courses archive page.
<form action="urlishere">
- that's where you need to have<form action="example.com/customposttype/
. Then, create a custom template for that archive so if$_POST['s']
is not empty, it searches and displays search results instead of just the normal archive. – WebElaine Commented May 5, 2020 at 17:41