Title: Exclude admin from custom function
Last modified: August 21, 2016

---

# Exclude admin from custom function

 *  [dealfiles](https://wordpress.org/support/users/dealfiles/)
 * (@dealfiles)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/exclude-admin-from-custom-function/)
 * I took over a WP site that was developed by another person. They created a custom
   function in functions.php named wp_authors_directory (see code below). They then
   created a page template to display the results of the function (see code below).
 * The problem is, it appears to me as though the function is designed to exclude
   the admin from the directory, but the admin is not being excluded. Both the user
   name and the nickname of the admin are “admin” but it is still not being excluded.
   Can someone help?
 * Here is a link to the directory page where the results are rendered, admin is
   displaying at the top:
 * [http://networkoftacoma.com/member-directory/](http://networkoftacoma.com/member-directory/)
 * Very much appreciated!
 * functions.php code:
 *     ```
       function wp_authors_directory($args = '') {
   
       	global $wpdb;
       	$my_base = get_bloginfo('url');
   
       	$defaults = array(
       		'optioncount' => false, 'exclude_admin' => true,
       		'show_fullname' => true, 'hide_empty' => false,
       		'feed' => '', 'feed_image' => '', 'feed_type' => '', 'echo' => true
       	);
   
       	$r = wp_parse_args( $args, $defaults );
       	extract($r, EXTR_SKIP);
   
       	/** @todo Move select to get_authors(). */
       //	$authors = $wpdb->get_results("SELECT ID, user_nicename from $wpdb->users " . ($exclude_admin ? "WHERE user_login <> 'admin' " : '') . "ORDER BY display_name");
   
       	$authors = $wpdb->get_results("SELECT ID, user_login, meta_key, meta_value from {$wpdb->users} LEFT JOIN {$wpdb->usermeta} ON {$wpdb->usermeta}.user_id = {$wpdb->users}.ID WHERE {$wpdb->users}.user_login NOT LIKE 'unverified%' AND meta_key LIKE 'last_name' ORDER BY meta_value");
   
       	foreach ( (array) $authors as $author ) {
       		$author = get_userdata( $author->ID );
       		$name = "$author->first_name $author->last_name";
       		$image = $author->userphoto_thumb_file;
       		$image_width = $author->userphoto_thumb_width;
       		$image_height = $author->userphoto_thumb_height;
       		$company = $author->company;
       		$category = $author->business_category;
       		$network_role = $author->network_of_tacoma_role;
       		$phone = $author->phone;
       		$fax = $author->fax;
       		$email = $author->user_email;
       		$website = $author->user_url;
           $link = '<a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Details About %s"), attribute_escape($author->display_name)) . '">' . $name . '</a>';
   
           if ($website == null ) {
             $website = 'mailto:' . $email;
           }
   
           if ($image == null ) {
             $image = 'no_photo.gif';
           }
   
           echo '<div class="member clearfix">
                   <div class="member-thumb">
                     <a href="' . get_author_posts_url($author->ID, $author->user_nicename) . '" title="' . sprintf(__("Details About %s"), attribute_escape($author->display_name)) . '"><img src="' . $base . '/wp-content/uploads/userphoto/' . $image .'" width="' . $image_width . '" height="' . $image_height . '" alt="' . $name . '" /></a>
                   </div>
                   <div class="member-details">
                     <h3>' . $link . '</h3
                     <dl class="clearfix">
                       <dt>Company</dt>
                         <dd><a href="' . $website . '" target="_blank">' . $company . '</a></dd>
                     </dl>
                     <dl class="clearfix">
                       <dt>Business Category</dt>
                         <dd><a href="' . $website . '" target="_blank">' . $category . '</a></dd>
                     </dl>
                     <dl class="clearfix">
                       <dt>Network Role</dt>
                         <dd>' . $network_role . '</dd>
                     </dl>
                     <dl class="clearfix">
                       <dt>Phone</dt>
                         <dd>' . $phone . '</dd>
                     </dl>
                     <dl class="clearfix">
                       <dt>Email</dt>
                         <dd><a href="mailto:' . $email . '">' . $email . '</a></dd>
                     </dl>
                     <p><em>More about ' . $link . '</em></p>
                   </div>
                 </div>'
                 ;
   
       	}
       }
       ```
   
 * Directory page template code:
 *     ```
       <?php
       /*
       Template Name: Directory Template
       */
       ?>
   
       <?php get_header(); ?>
   
       			<div class="left-column">
       <?php include('side-main.php'); ?>
       			</div>
       			<div class="right-column">
               <?php wp_authors_directory(); ?>
       			</div>
       		</div>
         </div>
       <?php get_footer(); ?>
       ```
   

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/exclude-admin-from-custom-function/#post-4386080)
 * It’s not a good idea to have a user who’s login is ‘admin’. There are hundreds
   of hackers routinely trying to brute force attack WordPress installations with
   logins named ‘admin’. No user login named ‘admin’ makes such attacks completely
   useless.
 * Consider excluding users in the list by their user ID. I’m unsure of the correct
   SQL phrase to do this. I would use `get_users()` instead to get users with an
   author role while excluding certain ID’s.

Viewing 1 replies (of 1 total)

The topic ‘Exclude admin from custom function’ is closed to new replies.

## Tags

 * [arguments](https://wordpress.org/support/topic-tag/arguments/)
 * [exclude](https://wordpress.org/support/topic-tag/exclude/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/exclude-admin-from-custom-function/#post-4386080)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
