Support

Account

Home Forums General Issues Query Users from Tax Field (and children) Reply To: Query Users from Tax Field (and children)

  • No, setting the field to return the term object does not store the term object in the database. The only thing that ACF stores in the DB is the term ID, no matter what you want to return.

    You would need to get the parents of the term and then add them all to your query

    
    $args = array (
      'numberposts'   => -1,
      'order'     => 'ASC',
      'orderby'     => 'display_name'
    );
    $meta_query = array(
      'relation'  => 'OR', // this is required, default is AND
      array(
        'key'     => 'department',
        'compare'   => 'LIKE',
        'value'   => '"' . $queriedTaxTerm->term_id . '"',
      )
    );
    $ancestors = get_ancestors($queriedTaxTerm->term_id, 'your-taxonomy-slug-here', 'taxonomy');
    if ($ancestors) {
      foreach ($ancestors as $ancestor) {
        $meta_query[] = array(
          'key'     => 'department',
          'compare'   => 'LIKE',
          'value'   => '"' . $ancestor . '"',
        );
      }
    }
    $args['meta_query'] = $meta_query;
    $wp_user_query = new WP_User_Query($args);