Skip to content

Instantly share code, notes, and snippets.

@remcotolsma
Last active December 22, 2015 10:48
Show Gist options
  • Save remcotolsma/6460846 to your computer and use it in GitHub Desktop.
Save remcotolsma/6460846 to your computer and use it in GitHub Desktop.
WordPress action for WordPress User Query filter on author of specific post type.
<?php
/**
* User query post type
*
* @param WP_User_Query $query
* @see https://github.com/WordPress/WordPress/blob/3.6/wp-includes/user.php#L528
*/
function prefix_user_query_post_type( $query ) {
global $wpdb;
$post_type = $query->get( 'prefix_post_type' );
if ( ! empty( $post_type ) ) {
$query->query_where .= $wpdb->prepare( " AND $wpdb->users.ID IN ( SELECT DISTINCT post_author FROM $wpdb->posts WHERE post_type = %s )", $post_type );
}
}
add_action( 'pre_user_query', 'prefix_user_query_post_type' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment