Hi there @epswp ,
You are right. This is the default way SportsPress shows the Staff of a Team. You can change it so as it respect the Roles Order value by copying the team-staff.php
template file from wp-content/plugins/sportspress/templates/
to wp-content/themes/your-child-theme/sportspress/
and use the following code:
<?php
/**
* Team Staff
*
* @author ThemeBoy
* @package SportsPress/Templates
* @version 2.5.5 (MODIFIED)
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
if ( ! isset( $id ) ) {
$id = get_the_ID();
}
$team = new SP_Team( $id );
$members = $team->staff();
$link_staff = get_option( 'sportspress_team_link_staff', 'no' ) === 'yes' ? true : false;
// Get role terms and sort them by
sp_order
$role_terms = get_terms( array(
'taxonomy' => 'sp_role',
'hide_empty' => false,
) );
if ( $role_terms ) {
usort( $role_terms, 'sp_sort_terms' );
}
// Create a mapping of role names to their order
$role_order = array();
foreach ( $role_terms as $index => $term ) {
$role_order[ $term->name ] = $index;
}
// Function to get the order of the role
function get_role_order( $staff, $role_order ) {
$staff_object = new SP_Staff( $staff->ID );
$staff_roles = $staff_object->roles();
if ( empty( $staff_roles ) ) {
return PHP_INT_MAX; // If no roles, put at the end
}
$role_names = wp_list_pluck( $staff_roles, 'name' );
// Find the first matching role in the defined order
foreach ( $role_names as $role_name ) {
if ( isset( $role_order[ $role_name ] ) ) {
return $role_order[ $role_name ];
}
}
return PHP_INT_MAX; // If role is not in the defined order, put at the end
}
// Sort the staff based on their roles
usort( $members, function( $a, $b ) use ( $role_order ) {
$a_order = get_role_order( $a, $role_order );
$b_order = get_role_order( $b, $role_order );
if ( $a_order === $b_order ) {
return 0;
}
return ( $a_order < $b_order ) ? -1 : 1;
});
foreach ( $members as $staff ) :
$id = $staff->ID;
$name = $staff->post_title;
$staff = new SP_Staff( $id );
$roles = $staff->roles();
if ( ! empty( $roles ) ) :
$roles = wp_list_pluck( $roles, 'name' );
$name = '<span class="sp-staff-role">' . implode( '<span class="sp-staff-role-delimiter">/</span>', $roles ) . '</span> ' . $name;
endif;
?>
<h4 class="sp-staff-name"><?php echo $link_staff ? '<a href="' . esc_url( get_permalink( $id ) ) . '">' . wp_kses_post( $name ) . '</a>' : wp_kses_post( $name ); ?></h4>
<?php
sp_get_template( 'staff-photo.php', array( 'id' => $id ) );
sp_get_template( 'staff-details.php', array( 'id' => $id ) );
endforeach;
Thanks,
Savvas