0

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

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

4

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 :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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