Skip Navigation

[Resuelto] Use wpv_filter_query to filter by Post ID match to an Array

This support ticket is created hace 2 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por benjaminJ-3 hace 2 años, 6 meses.

Asistido por: Shane.

Autor
Mensajes
#2318689

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;
}
#2318803

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: 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

#2318845

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;
}
Este ticket ya está cerrado. Si eres cliente de Toolset y necesitas ayuda relacionada, abre un nuevo ticket de soporte.