Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Show list of users on the frontend
- * // https://wpcrumbs.com/how-to-list-users-using-wp-user-query-and-shortcodes/
- **/
- function show_users_lists($atts) {
- // I don't use shortcode_atts because I want to have a dynamic number of attributes
- $query = new WP_User_Query($atts);
- $results = $query->get_results();
- // no results
- if (empty($results)) {
- return;
- }
- // when we have results
- ob_start();
- echo '<ul>';
- foreach ($results as $item) {
- ?>
- <li>
- Name: <a href="<?php echo get_author_posts_url($item->ID); ?>">
- <?php echo esc_html($item->display_name); ?>
- </a>
- <br />
- <?php echo 'Email: ' . esc_html($item->user_email); ?>
- <br />
- </li>
- <?php
- }
- echo '</ul>';
- return ob_get_clean();
- }
- add_shortcode('user_lists', 'show_users_lists');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement