1//NEW CLEAN way (WP 5.5.0 >=) of passing variables to template parts
2
3$data = array('foo'=>'bar');
4
5//add your variables as a third parameter
6get_template_part( 'template-parts/file', 'name', $data );
7
8//In the template part itself: (IMPORTANT NOTE: the name of the variable has to be args)
9echo $args['foo'];
1<?php
2get_header();
3
4// etc.
5
6// In the main template file
7$users = new \WP_User_Query( [ ... ] );
8
9foreach ( $users as $user )
10{
11 set_query_var( 'user_id', absint( $user->ID ) );
12 get_template_part( 'template-parts/user', 'contact_methods' );
13}