WordPress users.php table, custom search

Viewed 53

I want to filter users in the WordPress users.php page based on custom filters that find customers binded to managers, hooking pre_get_users.

in reference to articles like https://pressidium.com/blog/wordpress-admin-tables-add-custom-filters/

I've created my custom HTML select node listing any manager

enter image description here

the problem is that when I filter users, this ⬇ script trigger at any (user) queries on the same page.

So, if we have zero users found (or users that aren't managers), I get the e empty dropdown because the query has been filtered.

How can I filter only the table result?

$screen = get_current_screen();

if (!is_admin() || !$screen || 'users' !== $screen->base) { // https: //www.forumming.com/question/20902/custom-default-filtering-in-the-user-admin-panel-disables-the-other-sortable-columns
    return $query;
}

if (!isset($_GET['filter_by_assigned_manager']) || !intval($_GET['filter_by_assigned_manager'])) {
    return $query;
}

// my custom filters ...

enter image description here

Edit

the only solution I found till now is to add a global counter, because the first query is that I want

add_filter('pre_get_users', 'filter_users_manager_id');
function filter_users_manager_id($query) {
  global $counter_users_query;
  // ...
  if (++$counter_users_query != 1) return $query;
  // ...
0 Answers
Related