Last active
December 22, 2015 10:48
-
-
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.
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 | |
/** | |
* 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