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

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


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


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

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

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

Is there a specific reason you aren't using WP_User_Query? It would make it easier to do what you want to. You can read up on it here. Something along these lines would solve your problem, as far as I understand it: $args = array( "meta_key" => "ArtistCategory", "meta_value" => "X" //or "Z" ); $authors = new WP_User_Query($args); if ...


1

Use function get_users() $users = get_users(); foreach ($users as $user) { echo $user->ID; echo $user->display_name; the_author_image($user->ID); echo $user->description; }


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

In your case you can save your time the trouble by using Members List Plugin which allows you to create a post on your wordpress blog that lists all your wordpress members. When viewing the list of members you can also search through your members according to first name, last name, email address, URL or any other number of user meta fields ...


1

Your snippet is a little too verbose to follow (and it's late here) so this is more of an alternate take. I think that forking wp_list_author() might be overkill here. It would be more elegant to hook inside user search and accurately slice the portion of authors you need. Here is some example code I came up with: ...


1

Think I've figured it out. Here's the code I used courtesy of this thread on the WP Support Forum. Just replace ()<?php the_author_posts_link(); ?>() with whatever excerpt code you want to use. And Voila! <?php //list 5 latest authors $authors = array(); $count = 0; $args=array( 'post_type' => 'post', 'post_status' => 'publish', ...


1

Do the following to the foreach loop: echo '<pre>'; foreach($author_list as $author) { // author properties: // in detail: var_dump($author); // OR: overview: print_r($author); } echo '</pre>';


1

Hacky way of doing it: global $wpdb; $min_posts = 5; // Make sure it's int, it's not escaped in the query $author_ids = $wpdb->get_col("SELECT `post_author` FROM (SELECT `post_author`, COUNT(*) AS `count` FROM {$wpdb->posts} WHERE `post_status`='publish' GROUP BY `post_author`) AS `stats` WHERE `count` >= {$min_posts} ORDER BY ...


1

This is a simpler solution, if you want a total control over the code and don't want to use a query. $authors = get_users('role=author'); if(isset($authors) && !empty($authors)) { echo "<ul>"; foreach($authors as $author) { $posts = get_posts(array('author'=>$author->ID)); //if this author has posts, ...


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.


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

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

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

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



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