Tag Info

Hot answers tagged

4

You can do that with a simple loop assuming that the users are also the authors of the post, create a template page, and copy the inside of your page.php to it. then replace the loop part with this code: <?php $args = array( 'post_type' => 'company-listing', //change this to your actual CPT name 'posts_per_page' => -1, //-1 to get all or ...


4

Basic setup <?php $args = array( 'orderby' => 'nicename' ); $users = get_users( $args ); foreach ( $users as $user ) { $avatar = get_avatar( $user->ID, '80' ); echo '<li><a href="' . $user->user_url . '">' . $avatar . '<br />' . ...


3

Basic debugging... $current_author = get_query_var('author'); var_dump($current_author); ... would reveal that $current_author is a string, not an object. The problem is that you are trying to use the string as an object in the query. get_posts( 'author='.$current_author->id.'&posts_per_page=1&order=DESC&orderby=post_date' ); Change ...


3

Either an array of row objects with properties the column names of the result of the SQL query - ie. the specified fields from the wp_users table or, if fields equals 'all_with_meta', an array of WP_User objects. The fields value defaults to 'all', which will return all the columns in the wp_users table, but can be overridden by passing an array of ...


2

You can use WP_User_Query class with 3.1 and higher, there was WP_User_Search class which is deprecated since 3.1, also see this article from Steve Taylor you may find it helpful - http://sltaylor.co.uk/blog/get-wordpress-users-by-role/


2

To answer your problems: Sorting by post count You can collect all the information you need in to an array and sort that array by number of posts , like this: //function to sort array by filed function authors_orderBy($data, $field){ $code = "if (\$a['$field'] == \$b['$field']) {return 0;} return (\$a['$field'] < \$b['$field']) ? 1 : ...


2

Looks like you'll want to use get_users and you might want to take a look at the source code behind wp_list_authors to info on how to use it.


2

The WP_User_Query class There's the WP_User_Query for exactly that. This class is an extension for the cores base wpdb class. The counting will therefore be saved inside the global $wpdb; object and is easy accessible. global $wpdb; $author_search = new WP_User_Query( array( 'role' => 'author' ) ); $author_list = $author_search->get_results(); ...


2

You can use the following: // prepare arguments $args = array( // search only for Authors role 'role' => 'Author', // order results by display_name 'orderby' => 'display_name' ); // Create the WP_User_Query object $wp_user_query = new WP_User_Query($args); // Get the results $authors = $wp_user_query->get_results(); // Check for results if ...


2

For now post_type support is not currently available for count_user_posts(), so put the below code in theme's functions.php file. function count_user_posts_by_type( $userid, $post_type = 'post' ) { global $wpdb; $where = get_posts_by_author_sql( $post_type, true, $userid ); $count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->posts ...


2

You could use count_many_users_posts(). $args = array( 'exclude' => array( 4, ), 'fields' => 'ID', ); $users = get_users( $args ); $user_posts = count_many_users_posts( $users ); foreach( $user_posts as $user => $posts ) { if( $posts < 3 ) { unset( $user_posts[$user] ); } } $user_ids = array_keys( $user_posts ); shuffle( ...


2

You can display author's list by using function wp_list_authors for more info : http://codex.wordpress.org/Function_Reference/wp_list_authors And for author Template Hierarchy see below link http://codex.wordpress.org/Author_Templates


2

get_the_author() takes no arguments and must be used within the Loop (I guess it's the case). /* get_the_author($spost->ID); Replace this. */ get_the_author(); // By this.


2

Sebastien's answer got me on the right track. I should not be using the_author, because I am not looking for the author of a post (My query is not returning a post, but a user), rather the name of the user. I changed: echo get_the_author($spost->ID); to echo $spost->display_name;


1

If you require customized solution then you can use user query like this. <?php $args = array( 'who' => 'authors', 'orderby' => 'display_name' ); $wp_user_query = new WP_User_Query($args); if ( ! empty( $wp_user_query->results ) ) { foreach ( $wp_user_query->results as $user ) { echo ...


1

Basic Query The following query will give you the five users with the most posts in a site. Using the HAVING and COUNT will be much faster than other queries. Especially faster than built in multi purpose WP queries. global $wpdb; $postCountSQL = <<<SQL SELECT post_author, COUNT( * ) AS count FROM {$wpdb->posts} GROUP BY ...


1

Your query needs to include an argument to specify the author, and would need to be inside one of your "author" Loops. In fact, I see no need to Loop over your author data twice. Once should be fine. $display_admins = false; $order_by = 'display_name'; $role = ''; // 'subscriber', 'contributor', 'editor', 'author' - leave blank for 'all' $hide_empty = ...


1

You need to add this code to the file functions.php. function custom_post_author_archive($query) { if ($query->is_author) $query->set( 'post_type', array('post-type', 'post') ); remove_action( 'pre_get_posts', 'custom_post_author_archive' ); } add_action('pre_get_posts', 'custom_post_author_archive');


1

You could try the following SQL query: "SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_author NOT IN (1,3,4)" to exclude authors 1,3 and 4. In general it would be more handy to retrieve the user ids automatically, so you wouldn't need to update your SQL query every time you want to exclude someone. You could for example use the user meta to ...


1

The Codex lists rand as the orderby string, not RAND. I suspect that either works but I haven't checked. But that isn't how I'd do this. I'd lean toward something like... $current_category_ID = getCurrentCatID(); $current_cat_id = $current_category_ID; $author_array = array(); $args = array( 'numberposts' => -1, 'cat' => $current_cat_id ); ...


1

Granted, I may be misinterpreting you. Your post is not very clear but ... category__and will require the posts to be in both categories. It sounds like you need posts in any of the categories. You should be using category__in so that you get an OR match on the categories instead of an AND match. showposts is deprecated. Both category__and and ...


1

This worked for me. $user_query = new WP_User_Query( array( 'search' => '*example.net*', 'search_columns' => array('user_url') )); $authors = $user_query->get_results(); The wild card to be used in the search string is '*' and not '%'. Also you have to include the 'search_columns' parameter with the following possible values search_columns = ...


1

Change your query from: SELECT COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url FROM '.$wpdb->comments.' WHERE comment_author_email != "" AND comment_type = "" AND comment_approved = 1 GROUP BY comment_author_email ORDER BY comments_count DESC, comment_author ASC LIMIT ...


1

echo count( get_users( array( 'role' => 'author' ) ) )


1

Figured it out, for anyone who needs help with this I'm sure you can use with categories/tags as well (can also use with radio inputs and checked="checked": <tr> <th><label for="sorority"><?php _e('Sorority is...') ?></label></th> <td><?php $sorority = get_the_author_meta( 'sorority', $user->ID ); ?> ...


1

I'm finding it a little hard to follow based on your comments, however if you want to add a <div> around each other then change your second foreach statement to; foreach ($uc as $key => $value) { $user = get_userdata($key); $post_count = get_usernumposts($user->ID); if ($post_count) { $author_posts_url = ...


1

Here's a simple example showing default avatars and lists all users with the role of author. foreach ( get_users( array( 'role' => 'author' ) ) as $user ) { echo get_avatar( $user->ID, '96', get_stylesheet_directory_uri().'/default-avatar.png', $user->nice_name ); }


1

Wordpress itself does not store this info directly in database... yet you have some elegant options: you can hook into "publish post" and update list of "active users" when someone posts his/her published, you can store this information then in options table in serialized array. In this array you can have list of authors and when they published their last ...


1

I don't know of a plugin but the easiest way is to just embed your stack flair: http://stackoverflow.com/users/flair For a more detialed solution I recommend you just fetch the Stack API using the the WordPress HTTP API, the docs are here: http://codex.wordpress.org/HTTP_API The Stack API is very easy to work with and returns JSON. For you reputation for ...


1

What you need here is to shuffle all the array elements & then display them. But since php's shuffle() function doesn't preserve array key associations, here's a version that does. function shuffle_assoc(&$array) { $keys = array_keys($array); shuffle($keys); foreach($keys as $key) { $new[(string)$key] = $array[$key]; } ...



Only top voted, non community-wiki answers of a minimum length are eligible