I have created a View which displays and allows users to filter results on my website. All filters in the view work well. However, the custom field filters do not work in a parallel WP archive. The two should be pretty much identical, allowing users to seamlessly go to the Search page (View) and then click on any category, keyword, etc., and still filter results in the same way.
lien caché - you can see the View here, click on any taxonomy to see the archive.
Archive: FilterArchives
View: FilterSearch
Taxonomy filters:
- Topics
- Traditions
- Languages
Custom fields filters:
- Publication Year
- Medium
- Difficulty
- Recommended Use
I need all those filters to be available on the following taxonomy archives
- Topics
- Traditions
- Languages
- Figures
- Keywords
I am not using different post types, so only apply to posts.
I am aware that the taxonomy filter for an archive that's currently displayed will not be available. That's fine, as long as the other filters work.
Can you please help me work out what's up with those filters in the Archive? Thanks!
Thank you for looking into this! It seems that the Use and Difficulty filters work now, but the Medium and Date don't. Could the same solution be applied to them?
We can offer you support and guide you in the right direction and share inputs that what filters you can use and where or how. We do not code the whole funcationality for you. I already help you with how to adjust the filters while using view and now with this ticket with archive.
You can take initiative and try to add the missing filters and adjust the code accordingly. If you require more help with such custom requirement, you are always welcome to contact any of our certified partners:
- https://toolset.com/contractors/
Thanks for taking the time. I can't afford a contractor as this is an academic, non-profit project. I just used ChatGPT 😉 I managed to get the Medium filter going and it's all pretty much almost there! The Year one is tricky and I worry that I'm almost there but get something wrong. Maybe the labels of the 'year-from' and 'year-to' are wrong? I'd be most obliged for any suggestions.
$year_meta_query = array('relation' => 'AND'); // Ensures both conditions apply
// Only add the year query if at least one condition is set
if (count($year_meta_query) > 1) {
$query->query_vars['meta_query'][] = $year_meta_query;
}
Unfortunately - the admin access details you shared with me is not working at this end.
Can you please send me working admin access details.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) 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 have set the next reply to private which means only you and I have access to it.
Ah, the 'this site can't be reached' turned out to be an issue I had to fix by calling in a backup and it looks like this was from before you made the changes. I now added the code you wrote + the medium part back into the toolset-custom-code.php - I hope it's ok.
There are so many moving parts in this, thanks for keeping track.
With your restore process there must be somthing is missing as when I click on the "Search" button it shows critical error. That was not the issue when I shared the solution before.
It's weird, it was only breaking on the custom field filters, not the taxonomy filters. I wanted to test if it's because of the custom code, so I deactivated it. It started working. Now I activated it and it still works. Switching it off and on again works? Odd... Anyway, it should work, I hope.
- I've adjusted the "pre_get_posts" hook code to "Custom Code" section offered by Toolset with code snippet namely "toolset-custom-code" as given under:
=> lien caché