Title: Use custom functions code
Last modified: August 19, 2016

---

# Use custom functions code

 *  [vonholmes](https://wordpress.org/support/users/vonholmes/)
 * (@vonholmes)
 * [15 years, 4 months ago](https://wordpress.org/support/topic/use-custom-functions-code/)
 * Hello,
 * I found a code in this forum a while back courtesty of Jim de Groot:
 *     ```
       $roles = array('administrator', 'editor', 'author', 'contributor', 'subscriber');
   
       /* Loop through users to search for the admin and editor users. */
       foreach( $roles as $role )
       {
         	// all users with admin or editor role
       	if($role == 'administrator' || $role == 'editor')
         	{
       	  	$this_role = "'[[:<:]]".$role."[[:>:]]'";
       	  	$query = "SELECT * FROM $wpdb->users WHERE ID = ANY (SELECT user_id FROM $wpdb->usermeta WHERE meta_key = 'wp_capabilities' AND meta_value RLIKE $this_role) ORDER BY user_nicename ASC LIMIT 10000";
       	  	$users_of_this_role = $wpdb->get_results($query);
       	  	if ($users_of_this_role)
       		{
       	    	foreach($users_of_this_role as $user)
       			{
       		    	$curuser = get_userdata($user->ID);
       		      	$author_post_url=get_author_posts_url($curuser->ID, $curuser->nicename);
       				echo "<div class='post'>";
       					echo "<a href='.$user_link.' title='.$curuser->display_name.'>";
       						echo "<h2>$curuser->display_name</h2>";
       					echo '</a>';
       					echo "<a href='.$user_link.' title='.$curuser->display_name'>";
       						echo get_avatar($curuser->user_email, '80', $avatar);
       					echo '</a>';
       					echo '<p>'.$curuser->description.'</p>';
       				echo '</div>';
       		    }
       	  	}
       	}
       }
       ?>
       ```
   
 * What I need to find out is how I can call this as a function? I’m sure this is
   really simple – but I have tried adding `function test() { …code… } around it
   with no results. If anyone could point out what i’m doing wrong I would be really
   grateful.

Viewing 1 replies (of 1 total)

 *  Thread Starter [vonholmes](https://wordpress.org/support/users/vonholmes/)
 * (@vonholmes)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/use-custom-functions-code/#post-1907283)
 * Can anyone help?

Viewing 1 replies (of 1 total)

The topic ‘Use custom functions code’ is closed to new replies.

## Tags

 * [levels](https://wordpress.org/support/topic-tag/levels/)
 * [role](https://wordpress.org/support/topic-tag/role/)
 * [user](https://wordpress.org/support/topic-tag/user/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 1 participant
 * Last reply from: [vonholmes](https://wordpress.org/support/users/vonholmes/)
 * Last activity: [15 years, 3 months ago](https://wordpress.org/support/topic/use-custom-functions-code/#post-1907283)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
