Skip to content
Advertisement

Search filter to show results on search page for custom post type

I have a filter that has select options for Wheel base and price. Wheel base is a custom taxonomy assigned to the vehicles post type. This taxonomy has two options SWB and LWB.

Here is the markup for my form:

JavaScript

When the search button is clicked, I want to search the vehicles post type and display those vehicles that match the filtered query. For example, if I have Short wheel base and £5000 - £10,000 selected form the dropdowns, I want to display all the vehicles that match that query.

To do this, I have created a search.php file, which looks like this:

JavaScript

Current behaviour:

If from the dropdown I select Short wheel base and £5000 - £10,000 and click the search button, it takes me to:

/search?wheel-base=swb&min-price=5000-10000&max-price=&post_type=vehicles

The above url is correct based on my search parameters. However, the page 404s.

  • When I’m on /search, it’ll echo the “Search Result for :” text.
  • When I’m on /search?wheel-base=swb&min-price=5000-10000&max-price=&post_type=vehicles – it’ll 404.

I have followed the WordPress codex to create a search page (a page for search exists in the admin with the URL /search and the search page template is applied).

Ideas on what I’m missing here?

Advertisement

Answer

Based on this post : https://wordpress.stackexchange.com/a/291661/205128

post_type appears to be a reserved name in wordpress (list)

Can you try to change post_type input name, or prefix it like mynamespace_post_type ?

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement