Sticky Users?
-
I have this shortcode to display a loop of user avatars with order by registration date.
function Profiles() { $args = array( 'orderby' => 'registered', 'order' => 'DESC', 'fields' => 'all_with_meta', ); $user_query = new WP_User_Query( $args ); if ( ! empty( $user_query->results ) ) { foreach ( $user_query->results as $user ) { ?> <div class="grid-item user-img-<?php echo $user->ID; ?>" rel="<?php echo $user->ID; ?>"> <a href="<?php echo $website; ?>" rel="<?php echo $user->ID; ?>" target="_blank"><?php echo get_avatar( $user->ID, 100 ); ?></a> </div> <?php } } else { echo 'No users found.'; } } add_shortcode('profiles', 'Profiles');If any user role changes to
sticky(a custom role) then that users move to top of the list. Default orderby should stay as registered for all other users in the loop. Oncestickyuser role is removed, it goes back to normal sorting.I gave it quite a bit thought and maybe if i can combine two arguments in a single
Wp_User_Querythat might do the trick?For example
$sticky_argshaverole__in => 'sticky'and$simple_argshave all othersroles => 'subscriber', 'customer', 'author'ORrole__not_in => 'sticky'argument. Then combining thisWp_User_Queryin a way that$user_query->resultsshows$sticky_argsusers list first and then$simple_argsuser list after that in the loop. I tried several codes and trying to think if statements but nothing works so far. Would appreciate the help.
The topic ‘Sticky Users?’ is closed to new replies.