WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to achive this in sidebar.List of 10 latest permalinks(post titles) from contributors ?

share|improve this question

you can use the author parameter of WP_Query

here is a simple function to get you going with a hook to a shortcode and another hook to render this shortcode inside a simple text widget:

function ten_latest_of_contributers($atts = null){
global $post;
//store the current post data
$temp = $post;
$contributors = get_users(array('role'=> 'contributor'));
//then create an array of contributors ids

$contributors_ids = array();
foreach ($contributors as $user) {
    $contributors_ids[] =  $user->ID;

//then create a new query and use the author parameter
$con_query = new WP_Query(array(
    'author' => implode( ',', $contributors_ids ),
    'post_type' => 'post',
    'posts_per_page' => 10));

//all that is left is to loop
$re = '<ul>';
    $re .= '<li><a href="'.get_permalink($post->ID).'">'.get_the_title($post->ID).'</a></li>';
$re .= '</ul>';
//reset the current post data
$post = $temp;

//return the list
return $re;
// hook your shortcode

//render shortcodes in widgets
add_filter('widget_text', 'do_shortcode');

Paste this code in your theme's functions.php and then just enter [ten_latest_con] inside a text widget.

share|improve this answer
Internal Server Error when i put code in functions.php – user4490 Jul 17 '11 at 20:45
Create a pastebin of your functions.php – Bainternet Jul 18 '11 at 4:55
pastebin.com/33hYM0DF – user4490 Jul 18 '11 at 7:29
Ok i've updated the code, there were a few syntax errors but now its tested and works fine. – Bainternet Jul 18 '11 at 8:22
tnx, I will try this code, but Im curious about insert small excerpt toghether with post titles, and maybe user photo also..Is this hard task to accomplish? – user4490 Jul 19 '11 at 10:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.