[Resolved] image custom field as view query filter
This thread is resolved. Here is a description of the problem and solution.
Problem:
The customer wanted to display only posts with a custom image field in her view. However, when attempting to add a filter for this custom image field, it was not listed, nor were any other custom image fields.
Solution:
After further investigation, it was confirmed that the custom image fields not appearing in the filter section is expected behavior. We suggested using a wpv-conditional shortcode to test if the image exists as a workaround and provided a link to additional code that could help. Rita decided to rework the website to make images a required element when creating profiles.
Hi there
I have a view where I only want to display posts that have a custom image field. That is 'custom-image-field' is DIFFERENT from ' '.
The field belongs to my 'media group' custom field group - see attached screenshot. Its very strange but in this view and any other view on this site, when I click 'add a new filter' the image custom field I wish to filter by is not listed, nor are any of the other custom image fields... I don't know why not...
Hoping you can point me in the right direction.
Rita
Thank you for contacting us and I'd be happy to assist.
It is possible that this is happening due to a conflict issue, could you please try to test this problem in the minimal environment,
To do that, Please disable all non-Toolset plugins and activate a default theme (Twenty Twenty Three for example) . And then see if the problem exist.
If it doesn't work, I'll need to see how this CPT and view is set up in the admin area and to debug it closely.
Can you please share temporary admin login details along with a link to a page where this view can be seen?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.
I checked this but so far I couldn't find a fix for it.
I'd like to ask permission to make a copy/staging version of your site where I can debug this closely without affecting the live site.
I'll make sure to delete this copy as soon as we get this issue fixed.
I'm afraid of debugging directly on the live site and cause issues to your visitors. Also, it is important to test a different setup as part of the troubleshooting.
Thank you for your patience while I investigated it. I tested this on a fresh new WordPress install with Toolset and I figured out that this is the expected behavior for the custom image fields not show up in the filter section among the other custom fields.
I'm going to check internally if it is possible to implement it or suggest as a feature request, but as a workaround in the meantime you could use a wpv-conditional shortcode to test if the image exists or implement the code my colleague shared here after replacing the custom image field name:
Thanks very much for taking a look Mateus.
I have already tried the option to add that filter to functions.php but it breaks all the other search filters in the view. I have now reworked the way the website manages profiles in general and made images a required element when the user creates a profile. This is not what we were aiming for but it will have to do.
I'll close this ticket now.
Thanks again.
Rita