[Resolved] A view which shows posts of a certain post type and taxonomy but also searchable
This thread is resolved. Here is a description of the problem and solution.
Problem:
A view which shows posts of a certain post type and taxonomy but also searchable
Solution:
You should setup archives with custom search in such a way that you should pass it the post type as URL param for which you want to display the posts.
Hi there, I know what I am trying to do sound complex but I'll give my best to explain what I want to do and maybe it's actually quiet easy to achieve.
I have a bunch of different post types (Planes, Boats, Cars) and they all share a common hierarchical taxonomy. There are multiple parent terms in the taxonomy and each parent has multiple children.
I have 3 overview pages which only lists the parent terms of the taxonomy - one for the boats, one for the planes and one for the cars. For this I created 3 different views which display the terms as a grid and when you click on them, I want to show another view or archive page which shows all the entries which are assigned to the children of the parent I clicked on.
An example:
The parent level term is the manufacturer and the child level term is a certain model. I now have a Toyota Landcruiser as a Car which has only the Landcruiser child term assigned.
On the car overview I see all car brands like toyota, bmw etc. When I click on Toyota, I want to see all cars which have one of th Toyota children (e. g. Landcruiser or Hilux) assigned.
On that view or archive, I want then to show a search to further filter the results.
I want a text searchbox, a dropdown which shows all the toyota models (Landcruiser, Hilux etc). and maybe other filters for the custom fields I added to cars (e. g. price and location).
Furthermore I want to show a map but I am completely stuck right now and I'm trying to make this work for a few days already, making no progress.
I think in the overview I need to link to an archive page and pass the selected taxonomy id as a query parameter but then the search would overwrite it, wouldn't it?
I assume we are talking about archive page of custom taxonomy, the taxonomy filter on same custom taxonomy won't work as expected in the taxonomy archive page:
I suggest you setup a normal post view with custom search form for it.
I think a custom view is the way to go also, but these are the points I have trouble with:
1. When on the overview, I click on "Toyota", I can pass the taxonomy id to the destination page by using a link like: hidden link;
2. On the destination page I want to display a View with search and layout. The search should have a "Model" dropdown, which shows all the Toyota models. The Taxonomy is hierarchical so Toyota is the parent and Hilux and Landcruiser are children of Toyota.
3. On the destination page, when the ?taxonomy-id={id-for-toyota}, I want to sow all toyota cars. If I select Hilux from the dropdown in the search, I want to only show Toyota Hilux cars. If I reset the filters, I want to show all Toyota cars again
4. The very same page should show all BMW cars, if I use the link hidden link{id-for-mercedes} and the dropdown in the search shall only show BMW models like "3 series", "i3" and "5 series"
Luo is on vacation. This is Minesh here and I'll take care of this ticket and try to help you further to achieve solution you were looking for. Hope this is OK.
Well - I think what you need is achieved with post view with custom search but I need to check your current setup and please share problem URL so I can look at the issue and check how to achieve what you need.
Could you please share test site access details with problem URL.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
When you say you want to filter by post type - do you mean that you also want to pass post type as URL param Or you want to have different view for each post type?
Since I share the taxonomy between post types, Ideally I would setup the result page only once and pass in the post type as param but it would be totally fine if I had 3 differen result pages, one for each post type - whatever is easier to achieve.
Also ok:
.../cars?manufactuerer=toyota
.../boats?manufactuerer=champion
.../planes?manufactuerer=airbus
The most important thing is to limit the dropdown which shows the manufactuerer taxonomy (in the search) to only those direct children of the provided term via URL and that I can search and reset the search but still only show posts for that post type and manufactuerer.
2)
Also ok:
.../cars?manufactuerer=toyota
.../boats?manufactuerer=champion
.../planes?manufactuerer=airbus
The both way would be doable with little custom programming but better and straight forward will be to create a post type archive for your post types cars, boats and planes with custom search. So 2nd option is more straight forward.
Now, once you setup your archives with custom search, the main query is it should only display the children of the taxonomy term toyota OR champion OR airbus. The thing is that, there is no way to filter the taxonomy filter dropdown but there is a workaround. You should use custom Javascript code to remove the unwanted options from the taxonomy filter dropdown.
What you should do it grab the URL param of taxonomy term and only display options which are child belongs to that term and remove unwanted options from taxonomy dropdown using the custom JS code.