I have the following code who should work fine. But Wordpress is crashing. What's wrong?
echo "<ul>";
$usernames = $wpdb->get_results("SELECT user_nicename, user_url FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
foreach ($usernames as $username) {
echo '<li><a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";
}
echo "</ul>";
I have the following code who should work fine. But Wordpress is crashing. What's wrong?
echo "<ul>";
$usernames = $wpdb->get_results("SELECT user_nicename, user_url FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
foreach ($usernames as $username) {
echo '<li><a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";
}
echo "</ul>";
Share
Improve this question
edited Jan 21, 2019 at 15:48
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Jan 21, 2019 at 15:17
Nicolas SursockNicolas Sursock
1
2
- 1 What does it mean "crashing"? Please edit the question providing enough information. – Max Yudin Commented Jan 21, 2019 at 15:21
- There is nothing wrong with the above code, it works for me. You must have another error outside of the code you provided. – RiddleMeThis Commented Jan 21, 2019 at 15:25
1 Answer
Reset to default 0You should try using the get_users
function.
https://codex.wordpress/Function_Reference/get_users
Example:
get_users('orderby=meta_value&meta_key=user_registered');