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

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

link|improve this question

feedback

1 Answer

up vote 2 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 :)

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

Your Answer

 
or
required, but never shown

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