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 ...


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

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

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

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

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

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

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 ...


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

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

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

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 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

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

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

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

try something like this... you need to first call global $post; then get the author id like $author_id = $post->post_author;


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]; } ...


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

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

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

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

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


1

count_users() should give you an array of all the required user counts. You can use it like this. $user_counts = count_users(); $authors = $user_counts['avail_roles']['author']; //Get the author count $subscribers = $user_counts['avail_roles']['subscriber']; //Get the subscriber count echo $authors. ' Authors so far'; echo $subscribers. ' ...


1

First, Explaining Loops You're dealing with two kinds of "loops." The first is a loop in PHP, the second is a loop in WordPress. Loop in PHP kaiser gave you some code that will generate a list of authors on your site. You can iterate through this list and print information on the screen. // Fetch an array of authors from WordPress and store it in the ...


1

Use internal/built-in classes WP got … the WP_User_Query class. You can easily query for users of a role and return only those fields, that you actually need. wp_list_authors(); Example code $authors = new WP_User_Query( array( 'role' => 'editor', 'fields' => array( 'first_name', 'last_name' ) ) ); Then ...


1

I doubt you're going to be able to repurpose WP-PageNavi for this, since you're not using the built-in queries at all. You should be able to roll pagination yourself, though, and still fall back on some of WordPress's built-in functionality. In particular, if your URL matches the pattern /meet-the-team/page/3/, the paged querystring variable will ...


1

$args = array( 'posts_per_page' => 1, 'author' => $author->ID ); $posts = new WP_Query( $args ); $count = count( $posts ); Put this right after the foreach, $count will now contain either 1 or 0, put it through an if statement to filter the output.



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