我想在wordpress admin user list
中按照我在列表中创建的account status
列创建过滤器。现在我想使用我的列值过滤此用户列表,此列位于我的custom-user-details
表中。我能够为过滤器创建下拉列表,但它无法正常工作。我试过的代码是 -
//Code to filter user list by Status
function admin_users_filter( $query ){
global $pagenow,$wp_query;
if ( is_admin() && $pagenow=='users.php' && isset($_GET['abc']) && $_GET['abc'] != '') {
$query->search_term = urldecode($_GET['abc']);
global $wpdb;
if (!is_null($query->search_term)) {
$query = $wpdb->get_results( " SELECT DISTINCT account_status FROM custom_user_details ORDER BY account_status ASC " );
}
}
}
add_filter( 'pre_user_query', 'admin_users_filter' );
add_action( 'restrict_manage_users', 'restrict_abc_manage_list' );
function restrict_abc_manage_list()
{
?>
<select name="abc" style="float: none;">
<option value=""><?php _e('Filter By Status', 'baapf'); ?></option>
<option value="1">Active</option>
<option value="2">Inactive</option>
</select>
<input id="post-query-submit" class="button" type="submit" value="Filter" name="">
<?php
}
请详细说明以获得更多说明 -