Skip to content

Instantly share code, notes, and snippets.

@gogrw
Created May 13, 2019 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gogrw/666d17105e99b9f98a2bbe2697a8f343 to your computer and use it in GitHub Desktop.
Save gogrw/666d17105e99b9f98a2bbe2697a8f343 to your computer and use it in GitHub Desktop.
Shortcode for Listing Users from Meta Data - Without Parameters
/**
* Shortcode for Listing Users from Meta Data on PDF REPORT
* Usage: [list_users_pdf]
*/
function pdf_users_from_meta() {
$user_query = new WP_User_Query( array(
'meta_key' => '{report_type:3}',
'meta_value' => '{which_report:1}',
'role__in' => wp_parse_list( '{which_state:2:value}' ),
) );
$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>' . $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_pdf', 'pdf_users_from_meta' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment