Tell us what you are trying to do?
how do I filter to only show posts id's in_array of $user_providers_array
Is there any documentation that you are following?
You deleted all the docs I would normally have followed to resolve this.
This is what I have so far:
//Return only service providers from the current user:
add_filter( 'wpv_filter_query', 'prefix_show_only_current_user', 101, 3 );
function prefix_show_only_current_user( $query_args, $view_settings, $view_id ) {
if ($view_id == 551) {
global $current_user;
var_dump($query_args);
$pType = (array) $query_args['post_type'];
$providers = (types_render_usermeta( 'user-s-service-provider-id', array( 'separator' => ',', 'user_current' => 'true') ));
$user_providers_array = explode (',',$user_prog_id);
if ( !is_admin() && in_array( 'service-provider', $pType ) ) {
//how do I filter to only show posts id's in_array of $user_providers_array
}
}
return $query_args;
}
Shane
Supporter
Languages:
English (English )
Timezone:
America/Jamaica (GMT-05:00)
Hi Benjamin,
Thank you for getting in touch.
You will actually use the "post__in" attribute to do this.
Here is an example below.
//Return only service providers from the current user:
add_filter( 'wpv_filter_query', 'prefix_show_only_current_user', 101, 3 );
function prefix_show_only_current_user( $query_args, $view_settings, $view_id ) {
if ($view_id == 551) {
global $current_user;
var_dump($query_args);
$pType = (array) $query_args['post_type'];
$providers = (types_render_usermeta( 'user-s-service-provider-id', array( 'separator' => ',', 'user_current' => 'true') ));
$user_providers_array = explode (',',$user_prog_id);
if ( !is_admin() && in_array( 'service-provider', $pType ) ) {
//how do I filter to only show posts id's in_array of $user_providers_array
$query_args['post__in'] = $user_providers_array;
}
}
return $query_args;
}
Thanks,
Shane
My issue is resolved now. Thank you!
For anyone who finds this thread in the future, I had an error in my $user_providers_array variable and I also found you don't need to call global $current_user; (I'm guessing the types_render_usermeta has that baked in).
Working code:
add_filter( 'wpv_filter_query', 'prefix_show_only_current_user', 101, 3 );
function prefix_show_only_current_user( $query_args, $view_settings, $view_id ) {
if ($view_id == 551) {
global $current_user;
$pType = (array) $query_args['post_type'];
$providers = (types_render_usermeta( 'user-s-service-provider-id', array( 'separator' => ',', 'user_current' => 'true') ));
$user_providers_array = explode (',',$providers);
if ( !is_admin() && in_array( 'service-provider', $pType ) ) {
$query_args['post__in'] = $user_providers_array;
}
}
return $query_args;
}