Opened 8 years ago
Last modified 8 years ago
#46394 new feature request
Create a Function to Allow the WordPress Search to Only Return Results from a Specified Post Type
| Reported by: | pauljohnknight | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | General | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
Description
Hi
I'd like to install the WP search box on a custom post type archive page and have it only return results from this custom post type.
Is there any way in the future WordPress could allow you to add a parameter to the get_search_form() function (or create a similar function) that would allow this?
An example being, if I had a custom post type called jobs, when I add the WP search box on the jobs archive page I could add 'jobs' as a parameter so it only returned matches from the jobs post type i.e. get_search_form('jobs')
This would be so awesome.
Note:
See TracTickets
for help on using tickets.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
You can already accomplish this using the pre_get_posts filter, reference here: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts for more information on how to put that together. Unless this doesn't cover your use-case for some reason, I doubt this will be something that gets implemented.