Hot answers tagged list-authors
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
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 />' .
...
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 ...
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
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/
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
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
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
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 ...
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
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.
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
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 ...
Only top voted, non community-wiki answers of a minimum length are eligible