php - Wordpress only show posts from specific author role -
php - Wordpress only show posts from specific author role -
i want include filter loop, posts authors user role appear. want show them in category e.g "verified authors", need check if right category in loop aswell.
this have got:
functions.php
function get_author_role() { global $authordata; $author_roles = $authordata->roles; $author_role = array_shift($author_roles); homecoming $author_role; }
loop in category template
<?php if(have_posts()) : while(have_posts()) : the_post(); //how check if author = specific role , check if category 'verifiedauthors" ? endwhile;endif; ?>
you can add together author query loop.
// illustration $atuhors_array = array( 1,4,5,3 ); $query = new wp_query( array( 'author__in' => $authors_array ) );
once must create array , add're looking authors array.
$blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' ); // array of wp_user objects. foreach ( $blogusers $user ) { $authors_array[]= $user->id;
after adding authors array, can utilize author query.
php wordpress loops
Comments
Post a Comment