Skip Navigation

[Resuelto] Filtering View Based on Relationship with Two Parents

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to filter a View using two one-to-many relationships, but I am only able to add one relationship filter using the GUI. I would like to be able to pass both parent post filter values into the View using shortcode attributes.

Solution: Use the wpv_filter_query API to apply multiple toolset relationships filters, and use any arbitrary shortcode attributes to pass values into the View.

add_filter( 'wpv_filter_query', 'query_two_rels_by_shortcode_atts',99,3 );
function query_two_rels_by_shortcode_atts( $query_args, $views_settings, $view_id) {
  global $WP_Views;
  $view_ids = array( 498 );
  
  if (in_array($view_id, $view_ids)){
    $shortcode_atts = array('childid'=>0, 'courseid'=>0);
    $viewSlug = get_post_field('post_name', $view_id);
    foreach($WP_Views->view_shortcode_attributes as $atts) {
      if($atts['name'] == $viewSlug) {
        $shortcode_atts = $atts;
        break;
      }
    }
    $child_id = $shortcode_atts['childid'];
    $course_id = $shortcode_atts['courseid'];
    $query_args['toolset_relationships'] = array(
      array(
        'role' => 'child',
        'related_to' => $child_id,
        'relationship' => 'household-child_household-enrollment',
      ),
      array(
        'role' => 'child',
        'related_to' => $course_id,
        'relationship' => 'household-course_household-enrollment',
      ),
    );
  }
  return $query_args;
}

Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/how-to-migrate-your-site-to-new-post-relationships/
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

This support ticket is created hace 6 años, 5 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Etiquetado: ,

Este tema contiene 15 respuestas, tiene 3 mensajes.

Última actualización por Beda hace 6 años, 1 mes.

Asistido por: Christian Cox.