Skip Navigation

[Resolved] Usin the wpv_filter_query to more than one user

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to pass more than one user id of author using wpv_filter_query hook

Solution:
You should pass the array of IDs with "author_in" argument.

You can find proposed solution, in this case, with the following reply:
=> https://toolset.com/forums/topic/usin-the-wpv_filter_query-to-more-than-one-user/#post-625158

Relevant Documentation:

This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 2 voices.

Last updated by rafaelL-2 6 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#625125

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

#625158

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".

#625207

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?

#625209

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.

#625239

It works! Thanks for your time Minesh, I have a related question but I will open another ticket to be ordered