Skip to content

Instantly share code, notes, and snippets.

@remcotolsma remcotolsma/gist:6460846
Last active Dec 22, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.