[Resolved] View: custom field filter doesn’t keep post relationship filter when filtering
This thread is resolved. Here is a description of the problem and solution.
Problem:
The user is filtering a view using a relationship field and a URL param. After filtering using AJAX, the view loses the filter because the URL parameter is not preserved.
Solution:
To fix this, we need to add a hidden field that will keep the value of the URL param. This needs custom code such as:
I have a post relationship filter that gets all the Works in an Edition:
Select posts in a Editions Works relationship that are related to the Post with ID set by the URL parameter edition_id.
When these results are shown, I have a custom field filter that can then further filter these results based on the field called Medium:
Select items with field:
Medium is a string equal to URL_PARAM(wpv-wpcf-medium)
This allows me to see all of that editions works that are SATB, SAATB, orchestra, etc. At this point the dropdown correctly shows me ONLY those mediums that exist for the specific edition I'm in.
However, as soon as a choose a medium, the original post relationship is lost and I can suddenly see ALL the mediums for ALL editions on the site.
Have a look at the screenshots attached.
So my question is: how do I keep the original post relationship filter in place when using the custom field filter?
Hello. Thank you for contacting the Toolset support.
Can you please share problem URL from where I can select the Editor and share access details so I can review your current setup.
*** 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 have set the next reply to private which means only you and I have access to it.
I logged into your website and checked this issue. When the AJAX search is performed and results are pulled the URL loses the edition_id. We can work around it by adding a hidden field to the view's search form that will hold the edition_id. This way, when AJAX calls have performed the view will get the edition_id from the hidden field and use it for filtering.
I added a snippet to Toolset->Settings->Custom Code that adds the hidden field: