WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

I have a custom post type ("News"), and a custum user role ("Friends").

How can I get the last "News" written by "Friends" ?

share|improve this question
up vote 3 down vote accepted

I would try the following (not tested)

<?php
    $friends = get_users( array( 'role' => 'friends' ) );
    $friend_ids = array();

    foreach( $friends as $friend ) 
        $friend_ids[] = $friend->ID;

    $news = new WP_Query( array( 'author' => implode( ',', $friend_ids ), 'post_type' => 'news', 'paged' => get_query_var('paged') ) );
?>

Note: 'friends' is the role ID, not the nice name. Then use the loop as normal :

<?php if ( $news->have_posts() ) : while ( $news->have_posts() ) : $news->the_post(); ?>  
    ...
<?php endwhile; endif; ?>
<?php wp_reset_postdata(); ?>

Hopefully that will work :)

share|improve this answer
    
Great, it works thanks ! – mike23 Apr 20 '11 at 17:47
    
You're welcome buddy :) – Cristian Apr 20 '11 at 18:37

Your Answer

 
discard

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.