wpdb LIKE request shows all database data
I would like to get a list of user_nicenames and the ID. But not all the usernames which is what i’m getting now. I understand I should use the % before and after the $name only nothing seems to be working. This is the only way to get some output I found till now;
global $wpdb; //get access to the WordPress database object variable //get names of all users $name = $wpdb->esc_like(stripslashes($_POST['name'])).'%'; //escape for use in LIKE statement $sql = "SELECT user_nicename, ID FROM $wpdb->users WHERE user_nicename LIKE %s "; $sql = $wpdb->prepare($sql, $name); $results = $wpdb->get_results($sql);
How do I limit the output to only user_nicenames starting with, so
$_POST['name'] .'%' in normal php code.
0sql, wp-query, wpdb 5 years 2017-12-08T10:54:37-05:00 2017-12-08T10:54:37-05:00 0 Answers 103 views 0
Leave an answer