[wp-trac] [WordPress Trac] #28160: Get authors user query in-efficient when dealing with large numbers of users.
WordPress Trac
noreply at wordpress.org
Wed May 7 10:15:20 UTC 2014
#28160: Get authors user query in-efficient when dealing with large numbers of
users.
-------------------------+------------------------------
Reporter: l3rady | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Users | Version: 3.9
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------+------------------------------
Comment (by l3rady):
I have a quick fix for the this but is incredibly hacky:
{{{
/**
* @var $q WP_User_Query
*/
add_action( 'pre_user_query', function ( $q ) {
global $wpdb;
if ( !isset( $q->query_where ) ) {
return;
}
$where_match = 'WHERE 1=1 AND ( (' . $wpdb->usermeta . '.meta_key
= \'' . $wpdb->prefix . 'user_level\' AND CAST(' . $wpdb->usermeta .
'.meta_value AS CHAR) != \'0\') )';
if ( $q->query_where !== $where_match ) {
return;
}
$q->query_from = 'FROM ' . $wpdb->usermeta . ' LEFT JOIN ' .
$wpdb->users . ' ON (' . $wpdb->users . '.ID = ' . $wpdb->usermeta .
'.user_id)';
$q->query_where = 'WHERE ' . $wpdb->usermeta . '.meta_key = \'' .
$wpdb->prefix . 'user_level\' AND ' . $wpdb->usermeta . '.meta_value !=
\'0\' HAVING ' . $wpdb->users . '.ID IS NOT NULL';
} );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28160#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list