I am working with hidden link to make their filters compatible with the Toolset view.
They wanted me to ask you:
We need to modify the argument of get_posts() function used in the blocks of Toolset View block because we need to pass argument 'supress_filters' => false .
Do you have any developer hook we can use for that?
Hi,
Thank you for contacting us and I'd be happy to assist.
Toolset views use WordPress Query class ( ref:https://developer.wordpress.org/reference/classes/wp_query/ ) and to filter this query for the posts view, you can use the "wpv_filter_query" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
I hope this helps and please let me know if you need any further assistance around this.
regards,
Waqar
Hi Waqar,
Their developer tried to add a post_where filter but is not affecting that section.
Their plugin basically we use the wordpress post_where filter to remove posts that shouldn't show.
post_where filter it's executed in WpQuery, but that section in our home page is not filtering for some reason.
Can I provide you access to where you can take a look?
Thanks for writing back.
If your goal is to exclude specific posts from the view's query, you can use the 'post__not_in' parameter with the 'wpv_filter_query' filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
https://developer.wordpress.org/reference/classes/wp_query/#post-page-parameters
For example, suppose you have a view with ID "12345" and you'd like to exclude the posts with IDs "67" and "89" from the view's output. The filtering function would look like this:
add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
// process if specific view
if ( !is_admin() && ( isset($view_settings['view_id']) && $view_settings['view_id'] == 12345) ) {
$query_args['post__not_in'] = array(67, 89);
}
return $query_args;
}
Using this example, you or your developer can make the list of posts to exclude dynamically, using the criteria that you have in mind.
Hi Waqur,
We couldn't get it to work.
They commented out their fuction that return the posts that needs to be excluded and I simply hardcoded the post id number like this: $query_args['post__not_in'] = ['1864'];
add_filter( 'wpv_filter_query', 'wpv_filter_query_func', 1000 , 3 );
function wpv_filter_query_func( $query_args, $view_settings ) {
// process if specific view
if ( !is_admin() ) {
// $query_args['post__not_in'] = get_geotargeted_posts();
$query_args['post__not_in'] = ['1864'];
}
return $query_args;
}
and it's still didn't remove the post from the view. Can I provide you access so you can take a look?
Thanks for the update and it is strange that the code didn't work for you.
I've set your next reply as private so that you can share temporary admin login details, along with the link to the 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.
Thank you for sharing the admin access.
It is strange that the post exclusion through "wpv_filter_query" is not working on this website.
Do I have your permission to download a clone/snapshot of the website?
( ref: https://toolset.com/faq/provide-supporters-copy-site/ )
This will help us in investigating this in more detail on a different server.
Hi Waqar,
Yes of course, please proceed.
Thank you for the permission and I've downloaded the website's clone.
I'll need to perform some tests and will update you with my findings as soon as it completes.
Thank you for your patience.
Hi Waqar,
Thank you for the follow-up! Looking forward to your findings.
Thank you for waiting, as I investigated this rather odd behaviour.
During troubleshooting, I noticed that some custom script is added in the view "All Resources For Home Page".
( screenshot: hidden link )
The custom function is working as expected to exclude the post with ID "1864", but after the page loading has completed, this custom script automatically triggers the search with a value in the hidden language field.
If you'll remove this custom script, you'll see that this post with ID "1864" will not be shown by the view.
My issue is resolved now. Thank you!