1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
<?php $st = (isset($_GET['usersearch']) ? $_GET['usersearch'] : '' ); ?> <form action="" method="get"> <label for="usersearch">Search Term:</label> <input name="usersearch" id="usersearch" value="<?php echo $st; ?>" type="text"> <input name="dosearch" type="submit" value="Submit"> </form> <?php //check permissions first! /*if (!current_user_can("create_users") ){ wp_die("Access denied, must be logged in as admin."); exit; } else*/ if( isset( $_GET['usersearch'] ) ){ //$wpdb needs to be made global, this lets us use it on a page template global $wpdb; //some cleanup to the search term, as well as caching it to $usersearch $usersearch = stripslashes( trim($_GET['usersearch']) ); //$wpdb->prepare() is a fast and safe method for performing a MySQL query $stmt = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta AS um WHERE ( um.meta_key='last_name' AND um.meta_value LIKE '%%%s%%') OR (um.meta_key='last_name' AND um.meta_value LIKE '%%%s%%') ORDER BY um.meta_value LIMIT 150", $usersearch, $usersearch ); //results are cached in the variable $results using get_col() $results = $wpdb->get_col( $stmt ); } ?> <table> <tbody> <?php //$metanames a simple array containing the names of the meta values //It will allow us to loop through them to keep the code simple and clean ?> <?php $metanames = array("first_name", "last_name") ; $links = "user_registered" ; ?> <table> <tbody> <?php foreach($results as $u){ echo "<tr>"; echo "<td>"; //$u is going to be the users id echo $u; echo "</td>"; //now we can loop through the $metanames variable foreach($metanames as $m){ echo "<td>"; echo esc_attr( get_user_meta( $u, $m, true ) ); echo "</td>"; } ?> <?php echo "<td>"; ?> <?php //foreach($links as $link){ ?> <?php $authorLinks = get_the_author_meta( 'user_login', $u, true ) ; $sanitized = sanitize_title_with_dashes($authorLinks); ?> <a href="<?php bloginfo('url'); ?>/author/<?php echo $sanitized ; ?>"> View </a> <?php //} ?> <?php echo "</td>"; echo "</tr>"; } ?> </tbody> </table> |