Title: Query posts using author custom meta
Last modified: August 22, 2016

---

# Query posts using author custom meta

 *  [emeraldmedia](https://wordpress.org/support/users/emeraldmedia/)
 * (@emeraldmedia)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/query-posts-using-author-custom-meta/)
 * I have a custom user meta field called ‘county’
    I have a custom post type called‘
   classes’
 * I want to query classes by all users whose ‘county’ meta is the same as the page
   ID.
 * Where I’m stuck is the post query. I’m using ‘author__in’ which expects an array
   of user ID’s. How do I do a user query here that will return an array of ID’s?
 *     ```
       $this_county = $post->post_name; //Use the ID of this page to determine which county we need
       $user_query = new WP_User_Query( array('meta_key' => 'county', 'meta_value' => $this_county) ); //Find users whose county is set to this county
       $args = array('author__in' => $user_query, 'post_type'=>'classes'); //Find classes by matched users
       ```
   

Viewing 1 replies (of 1 total)

 *  Thread Starter [emeraldmedia](https://wordpress.org/support/users/emeraldmedia/)
 * (@emeraldmedia)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/query-posts-using-author-custom-meta/#post-5279711)
 * Got it…
 *     ```
       $results = array();
       if ( ! empty( $user_query->results ) ) {
       	foreach ( $user_query->results as $user ) {
       		$results[] = $user->ID;
       	}
       } else {
       	echo 'No users found.';
       }
       $args = array('author__in' => $results, 'post_type'=>'classes'); //Find classes by matched users
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Query posts using author custom meta’ is closed to new replies.

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [emeraldmedia](https://wordpress.org/support/users/emeraldmedia/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/query-posts-using-author-custom-meta/#post-5279711)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
