Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @eyewebdesign

    Could you please provide a screenshot of the dropdown that you’re referring to?

    Regards,

    Thread Starter eyewebdesign

    (@eyewebdesign)

    Hi,

    Sure, below 2 screenshots, working for all users and not working for rejected users. Also below the code.

    Working dropdown: https://eyewebdesign.be/data/screenshot-working-dropdown.jpg
    Not working dropdown: https://eyewebdesign.be/data/screenshot-dropdown-not-working.jpg

    $global_init_agents;
    function eye_set_global_vars() {
    	global $global_init_agents;
    	$user_query = new WP_User_Query( array( 'role' => 'um_vertegenwoordiger' ) );
    	$global_init_agents = $user_query->get_results();
    }
    add_action( 'registered_post_type', 'eye_set_global_vars', 1 );
    /*** Sort and Filter Users ***/
    add_action('restrict_manage_users', 'filter_installers_by_agent');
    function filter_installers_by_agent($which)
    {
    	global $global_agents, $global_init_agents;
    	$agent_id = "";
    	if(isset($_GET['filter-agent_top']))	if($_GET['filter-agent_top'] != "") 	$agent_id = $_GET['filter-agent_top'];
    	//if(isset($_REQUEST['filter-agent_bottom'])) if($_REQUEST['filter-agent_bottom'] != "") 	$agent_id = $_REQUEST['filter-agent_bottom'];
    	
    	// template for filtering
    	 $st = '<select name="filter-agent_%s" style="float:none;margin-left:10px;">
    		<option value="">%s</option>%s</select>';
    
    	$options = "";
    	 // generate options
    	 foreach($global_init_agents as $user) {
    		 $selected = "";
    		 if($agent_id == $user->ID) $selected = "selected";
    		 $options .= "<option value=".$user->ID." $selected>". __( 'Installateurs onder ', 'eyewebdesign' ).$user->display_name."</option>";
    	 }
    
    	 // combine template and options
    	 $select = sprintf( $st, $which, __( 'Alle vertegenwoordigers', 'eyewebdesign' ), $options );
    
    	// output <select> and submit button
    	echo $select;
    	submit_button(__( 'Filter' ), null, $which, false);
    	echo '<input id="users-reset-filters" class="button" type="submit" value="Reset filters" name="users-reset-filters">';
    }
    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @eyewebdesign

    UM modifies the WP_User_Query when viewing the rejected table.
    Try using the $wpdb to retrieve the users by role. Here’s an example:

    global $wpdb; 
    $global_init_agents = $wpdb->get_results("SELECT *
    FROM {$wpdb->users} INNER JOIN {$wpdb->usermeta}
    ON {$wpdb->users}.ID = {$wpdb->usermeta}.user_id 
    WHERE {$wpdb->usermeta}.meta_key = 'wp_capabilities' 
    AND {$wpdb->usermeta}.meta_value LIKE '%um_vertegenwoordiger%'");
    

    Regards,

    Thread Starter eyewebdesign

    (@eyewebdesign)

      UPDATE: I just tested this and it returns an empty array, so that’s why I can’t loop through it…

    Hi,

    Thanks. How should I loop through $global_init_agents? What does $wpdb->get_results return? Because the foreach foreach($global_init_agents as $user) doesn’t work anymore

    Thanks
    Davy

    • This reply was modified 4 years, 7 months ago by eyewebdesign.

    @eyewebdesign

    Look at your usermeta table and the metakey is probably not ‘wp_capabilities’.
    wp should be replaced by your WP site base_prefix.

    Thread Starter eyewebdesign

    (@eyewebdesign)

    Indeed, how stupid of me. It works, thanks a lot!

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Thanks for letting us know how it resolved the issue.

    Regards,

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘dropdown with users on users.php?um_status=rejected’ is closed to new replies.