As far as I understand, I can filter a view with custom PHP. (The existing filter options are not enough in my case.) I have found several articles that describe how this should work, but for me already the hook does not work. Maybe you can help me.
I have set up a test installation here hidden link.
On the home page, I added a view via shortcode [wpv-view name="list-posts"].
In the functions.php I try to use the hook "wpv_filter_query". I use the Query Monitor plugin to debug the code (QM::...).
The code in functions.php is:
QM::error('a');
add_filter('wpv_filter_query', 'post_type_filter_func', 99, 3);
function post_type_filter_func($query_args, $settings, $view_id)
{
QM::error('b');
// code ...
return $query_args;
}
While "a" is output in the log, the "post_type_filter_func" function does not seem to be triggered (query monitor message "b"). What am I doing wrong? Can you nudge me in the right direction?
Thanks a lot!
Hi,
Thank you for contacting us and I'd be happy to assist.
I tested the code that you shared on my test website and it worked as expected.
Then I also tested your website's homepage after clearing the view's cache from WP Admin -> Toolset -> Views and was able to see both errors in the log.
( screenshot: hidden link )
You'll find more details on how the internal cache works for the view's output, in this reply:
https://toolset.com/forums/topic/caching-of-several-views-not-working-although-activated/#post-2380085
I hope this helps and please let me know if you need any further assistance with this.
regards,
Waqar
My issue is resolved now. Thank you!