Hi, Minesh helped me with some custom code on this topic:
https://toolset.com/forums/topic/custom-query-filter-with-multiple-conditions/page/2/
This is the custom code:
function func_remove_unwanted_posts( $query_args ,$view_settings, $view_id ) {
global $post;
global $current_user;
global $WP_Views;
if ( in_array($view_id, array( 9023, 19926, 18389) ) ) {
$wpvprofile = do_shortcode("[wpv-attribute name='wpvprofile']");
$custom_query = new WP_Query(
array(
'post_type' => 'follower',
'posts_per_page' => -1,
'author__in'=>array($current_user->ID),
'fields'=>"ids",
'meta_query' => array(
'relation'=>"AND",
array(
'key' => 'wpcf-followed-id',
'value' => array($wpvprofile, 9764),
'compare' => 'NOT IN'),
array(
'key' => 'wpcf-followed-id',
'compare' => 'EXISTS'),
)
));
$found_posts = $custom_query->posts;
$query_args['post__in'] = $found_posts;
}
return $query_args;
}
add_filter( 'wpv_filter_query', 'func_remove_unwanted_posts', 10, 3);
Now I found a problem with the custom code.
In the case of 'follower' CPT, the code is getting only posts where the author is the current_user. I need to exclude the other author's posts only when 'followed-id' filed value is DIFFERENT form 'wpvprofile' attribute.
I try to better explain the scenario.
Each user has a 'profile' CPT post asigned. Then I have the 'follower' CPT with the custom post field 'followed-id'.
Everytime a user starts following another user, I create a 'follower' post where the user who FOLLOW is the author and the FOLLOWED profile ID is stored in the 'followed-id' field.
On my stream I display activity from all the followed users, from the current user and from followers when the start following. I could display 3 different kind of messages:
1- CURRENT-USER begun following USER-44
2- USER-44 begun following USER-99
3- USER-55 begun following CURRENT-USER
What I don't want to show is the number 2. It is an activity form a user that the current user is following (so it is correctly quried by the View), but I want to remove it from the query, because it is not related to the current user.
So, the problem with the custom code is that it is excluding all the posts where the current user is not the author, but I need exclude them only when 'followed-id' is DIFFERENT from 'wpvprofile'.
I hope you can help me.
thanks