WordPress.org

Ready to get started?Download WordPress

Forums

Exclude Admin and stop blank user creation from Query (1 post)

  1. cjdsie
    Member
    Posted 1 year ago #

    I have this code below calling in two different users. The problem with it is that sometimes it will create a blank user or call the admin users that don't have any information associated with them like userphoto or name. How can I get my query to exclude those users and the not create a blank user.

    <?php
    		$order = 'user_nicename';
    		$user_ids = $wpdb->get_col("SELECT ID, user_nicename, display_name FROM $wpdb->users WHERE user_status = 0 ORDER BY $order"); // query users
    		$n = $user_ids;
    		$id1 = rand(1,count($n));
    		$id2 = rand(1,count($n));
    		while ($id1 == $id2) {
    		$id2 = rand(1,count($n));
    		break;
    		}
    		$user = get_userdata($id1);
    		?>
    
    		<a href="#" class="employee five columns alt-spacing captionfull bwWrapper item">
    			<?php
    			echo userphoto($id1);
    			echo '<div class="cover boxcaption">';
    			echo '<figcaption>'. $user->display_name .' | <span> '.$user->job_title.'</span></figcaption>';
    			echo '</div>';
    			?>
    		</a>
    
    		<section class="text five columns alt-spacing">
    			<?php the_excerpt(); ?>
    		</section>
    
    		<?php $user = get_userdata($id2);
    
    		?>
    		<a href="#" class="employee five columns alt-spacing captionfull bwWrapper item">
    			<?php
    			echo userphoto($id2);
    			echo '<div class="cover boxcaption">';
    			echo '<figcaption>'. $user->display_name .' | <span> '.$user->job_title.'</span></figcaption>';
    			echo '</div>';
    			?>
    		</a>

Topic Closed

This topic has been closed to new replies.

About this Topic