Created
May 13, 2019 14:09
-
-
Save gogrw/b4f4b549955d56970ea32b33ba8af1e1 to your computer and use it in GitHub Desktop.
Shortcode for Listing Users from Meta Data - Passing Merge Tags Through Parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Shortcode for Listing Users from Meta Data | |
* Usage: [list_users key="{report_type:3}" value="{which_report:1}" userrole="{which_state:2}"] | |
*/ | |
function users_from_meta($atts) { | |
$atts = shortcode_atts( array( | |
'key' => '', | |
'value' => '', | |
'userrole' => '', | |
), $atts ); | |
$user_query = new WP_User_Query( array( | |
'meta_key' => $atts['key'], | |
'meta_value' => $atts['value'], | |
'role__in' => wp_parse_list( $atts['userrole'] ), | |
) ); | |
$users = $user_query->get_results(); | |
if (!empty($users)) { | |
$results = '<table class=list_user_table> | |
<tr> | |
<td class=list_user_title1>Shop #</td> | |
<td class=list_user_title2>City</td> | |
<td class=list_user_title3>State</td> | |
<td class=list_user_title4>Franchisee</td> | |
<td class=list_user_title5>Consultant</td> | |
</tr>'; | |
foreach ($users as $user){ | |
$results .= '<tr> | |
<td class=list_user_td_left><a href=https://clearstone.gogrw.com/user/shop' . $user->Store_Number . '/>' . $user->Store_Number . '</a></td> | |
<td class=list_user_td>' . $user->City . '</td> | |
<td class=list_user_td>' . $user->State . '</td> | |
<td class=list_user_td>' . $user->display_name . '</td> | |
<td class=list_user_td>' . $user->Group . '</td> | |
</tr>'; | |
} | |
$results .= '</table>'; | |
} else { | |
$results = 'No users found'; | |
} | |
wp_reset_postdata(); | |
return $results; | |
} | |
add_shortcode( 'list_users', 'users_from_meta' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment