Created
November 8, 2022 02:09
-
-
Save nathan-roberts/9bb5d969ce9c3dca757602ab2b62dad0 to your computer and use it in GitHub Desktop.
Query posts by users roles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get all the user ID's for the specified user roles | |
* | |
* @param array $role | |
* @return array User ID's | |
*/ | |
function get_all_user_ids_by_user_roles($role) | |
{ | |
$users = get_users(array('role__in' => $role)); | |
$user_ids = array(); | |
foreach ($users as $user) { | |
$user_ids[] = $user->ID; | |
} | |
return $user_ids; | |
} | |
$roles = ['editor', 'administrator']; | |
$user_ids = get_all_user_ids_by_user_roles($roles); | |
$args = array( | |
'author__in' => $subscriber_ids, | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'posts_per_page' => -1, | |
'orderby' => 'date', | |
'order' => 'DESC' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment