I want to include a filter into the loop, so only the posts from authors with a certain user role appear. I want to show them in a certain category eg "verified authors", so i need to check if this is the right category in the loop aswell.
This is what I have got:
functions.php
function get_author_role()
{
global $authordata;
$author_roles = $authordata->roles;
$author_role = array_shift($author_roles);
return $author_role;
}
loop in category template
<?php
if(have_posts()) : while(have_posts()) : the_post();
//how to check if author = specific role and check if category 'verifiedauthors" ?
endwhile;endif;
?>
You can add author query to your loop.
// Example
$atuhors_array = array( 1,4,5,3 );
$query = new WP_Query( array( 'author__in' => $authors_array ) );
Once you must create array and Add're looking for authors this array.
$blogusers = get_users( 'blog_id=1&orderby=nicename&role=subscriber' );
// Array of WP_User objects.
foreach ( $blogusers as $user ) {
$authors_array[]= $user->ID;
After your adding authors to array, now you can use author query.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.