Display the total number of users of WordPress
April 29, 2009
If your wordpress allow user registration, what about displaying the total number of registered users? This simple code will allow you to do it easily. Simply paste the following code anywhere in your wordpress theme files: $users = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"); echo $users." registered users."; Once you saved the file and refreshed your wordpress, the total number of users will be displayed. Read More →
Get all wordpress users having a specific role
March 12, 2009
Sometimes as a WordPress plugin developer or a WordPress theme developer, you want to get all of the users with a specific role. For example, all editors. To easily get all users of a role, the first thing to do is to create the function. To do so, paste the following code in your functions.php file: function getAllUsersWithRole($role) { $wp_user_search = new WP_User_Search($usersearch, $userspage, $role); return $wp_user_search->get_results(); } The getAllUsersWithRole() function returns an array containing... [Read the full story]
List wordpress latest registered users
November 15, 2008
If you allow user registration on your blog, listing your latest users along with their url could be a good thing to get more users. But there’s no WordPress function to do that…… Just paste the following code anywhere on your template. It will list your 5 latest registered users. If you want to get more or less users, simply change the 5 in the SQL query. <h2>Latest registered users</h2> <ul> <?php $usernames = $wpdb->get_results("SELECT user_nicename, user_url FROM $wpdb->users... [Read the full story]
Only display private posts to logged wordpress users in the loop
November 11, 2008
If you want to be able to display private posts only to registered users within the loop, I’m explaining how to do it, with a code exemple you can re-use on your blog. you’ll have to define a custom field named private, with true as a value, to each private post will have. In our WordPress loop, we’ll check if the post have a private custom field, and if true is its value. If yes, we’ll check out if the user is logged in. If he is, the post will be displayed. Otherwise, it will not. Replace your current WordPress... [Read the full story]
How to remove ads for registered users
October 22, 2008
Hiding ads for registered users is a good idea since it can help you to decrease the risk of being smart-priced by Adsense. To achieve this, we just have to use the is_user_logged_in() function, which returns true is an user is logged in. This recipe is very easy to use, just paste the following code anywhere on your theme. if (!is_user_logged_in()) { // Insert Adsense (or whatever) code here } Read More →




















