Tell us what you are trying to do?
Usin the wpv_filter_query I want to restric the view based on one or more than 1 author.
The current code works using "author" as ID 4.
add_filter( 'wpv_filter_query', 'show_posts_non_loggedin_user',10,3);
function show_posts_non_loggedin_user( $query_args, $view_settings, $view_id ) {
global $current_user;
$types = (array) $query_args['post_type'];
$arraydevalores = plugin_is_page();
$commaseparated = implode(",", $arraydevalores);
//891 is my current view ID
if($view_id == 891 && in_array( 'upn', $types ))
{
$query_args['author'] = 4;
}
return $query_args;
}
I currently have a function plugin_is_page() that returns an array with the 'ids' that I want to use. Example
Let's asume this:
$arraydevalores = plugin_is_page();
$arraydevalores will have two values into the array, 2 and 5 (I already checked that using print_r)
What I need is to improve the below code to do the same as now but using the values of the array as author, something like:
$query_args['author'] = $commaseparated ;
If I use something like $query_args['author'] = '2,3,4'; Works perfectly so maybe I am not using wpv_filter_query well?
--------------
I also tried using $query_args['author_in'] = array($commaseparated); with no luck
Is there any documentation that you are following?
I read API and a lot on the forum but didn't find what I am looking for.
Many thanks in advance
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Could you please try following argument:
$query_args['author__in'] = array($commaseparated);
Please notice the difference that you have only one underscore "author_in" and the code I shared has two underscores "author__in".
Hi there
I used
$query_args['author__in'] = array($commaseparated);
but show no results.
To confirm, I printed the $commaseparated values and the result is:
5,2
So I manually put this:
$query_args['author__in'] = array(2,5);
and works
I also make the following test:
$testingarray= array (2,4);
$arraycomma= implode(",", $testingarray);
then again I put
$query_args['author__in'] = array($arraycomma);
Still doesn't work :S
Can you take a look please?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
What if you try following code - it should work:
$query_args['author'] = "$arraycomma";
OR
$query_args['author'] = $arraycomma;
Could you please confirm which code works for you from above options.
It works! Thanks for your time Minesh, I have a related question but I will open another ticket to be ordered