Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

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.