• Good Morning,

    My goal is to display the profile data for each new registrant within a page. For example, I’d like to display first name, last name & address for all registrants that selected a certain value in a select list drop down.

    In my case, let’s say a new registrant chose the category “Watch Dealer” from a select list. I want to show only registrants that chose “Watch Dealer” on a page.

    I’m using a triple dependent drop down list with Register Plus to accomplish this. I can successfully store the values in the usermeta table, I just don’t know the best method to output it to a page as described above. my Register Plus registration page including triple dependent drop down list can be viewed here: https://la-jewelry-district.itegritygroup.com/wp-register

    Any advice on how to solve this would be very appreciated. Thank you in advance.

    Steve

Viewing 11 replies - 1 through 11 (of 11 total)
  • My goal is to display the profile data for each new registrant within a page. For example, I’d like to display first name, last name & address for all registrants that selected a certain value in a select list drop down.

    Here’s a snip of code you could use in your Page Template:

    <?php
    $blogusers = get_users_of_blog();
    if ($blogusers) {
    foreach ($blogusers as $bloguser) {
    $user = get_userdata($bloguser->user_id);
    //echo "<pre>"; print_r($user); echo "</pre>";
    $dealer1 = $user->dealer1; //dealer1 should be replaced by whatever meta_key is used with Register Plus Data
    if ($dealer1 == 'Watch Dealer') {
    echo 'User ID ' . $user->ID . ' ' . $user->user_firstname . ' ' . $user->user_lastname . ' is a Watch Dealer.';
    }
    }
    }
    ?>

    Thread Starter skozyk

    (@skozyk)

    Michael,

    Thank you very much for your quick response. The code snippet you provided was absolutely what I was looking for. It works perfectly. I also appreciate you commenting the code.

    After getting the code added to my site and working properly I realized that I don’t want to display the data until the admin approves the new user registration. I found that the unverified user info is stored in the user_login field of the wp_users table. I also see that the actual user name is stored in the user_nicename field. When a user has been approved the value in user_login equals user_nicename.

    Would you be willing to add the necessary code to the code you provided above to only show the data if a user has been approved by the admin? I’d also like to show the data in ascending alphabetical order by, let’s say, first name.

    Thanks again,

    Steve

    Easiest thing to do is to pick a sort field in wp_users that you can live with, then replace the get_users_of_blog(); with a construct using wpdb to get the users sorted, and exclude the unverified users.

    Thread Starter skozyk

    (@skozyk)

    Thanks Michael. I accomplished it by adding:

    if ($user->user_login == $user->user_nicename)

    Once the user is verified by the admin the user_login field is changed from unverified__xxxxx to the same value as the user_nicename field. So I check to see if user_login is equal to user_nicename.

    Do you see any potential problems doing it this way?

    Good solution. Will mark this resolved.

    Thread Starter skozyk

    (@skozyk)

    Last question Michael, How do display users in alphabetical order? I know how to do it with a SELECT statement and ASC, but I’m not sure how to do with the above method I’m using. Right now it displays by user_id.

    My thought is to use a wpdb construct instead of the get_users_of_blog.

    Thread Starter skozyk

    (@skozyk)

    I’ve been trying to solve how to get my results to display alphabetically by first_name from the usermeta table since your last post minus a few hours of shut eye and I feel I’m pretty well stuck. I realize this is getting beyond the scope of Register Plus and appreciate your consideration of help.

    I located the functions you use in your provided code and tried to modify them to include an ORDER BY $wpdb->first_name ASC (also tried some other methods). I copied these functions below for reference.

    One of the problems is the get_row function returns the results I need, however it doesn’t seem that you can use ORDER BY in the statement because it is looping through selecting single rows one at a time.

    I think what it comes down to is if each key in the usermeta table was stored in it’s own field, I’d be able to easily write a select statement that alphabetizes ASC, but because I need to alphabetize by a key in the meta_key field with values stored in the meta_value field, I’m having trouble. Do you have a solution for this?

    (WP functions used in above code snippet listed below for reference)

    get_users_of_blog()
    Defined at: * /wp-includes/user.php -> line 218

    /**
     * Get users for the blog.
     *
     * For setups that use the multi-blog feature. Can be used outside of the
     * multi-blog feature.
     *
     * @since 2.2.0
     * @uses $wpdb WordPress database object for queries
     * @uses $blog_id The Blog id of the blog for those that use more than one blog
     *
     * @param int $id Blog ID.
     * @return array List of users that are part of that Blog ID
     */
    function get_users_of_blog( $id = '' ) {
    	global $wpdb, $blog_id;
    	if ( empty($id) )
    		$id = (int) $blog_id;
    	$users = $wpdb->get_results( "SELECT user_id, user_login, display_name, user_email, meta_value FROM $wpdb->users, $wpdb->usermeta WHERE " . $wpdb->users . ".ID = " . $wpdb->usermeta . ".user_id AND meta_key = '" . $wpdb->prefix . "capabilities' ORDER BY {$wpdb->usermeta}.user_id" );
    	return $users;
    }

    —————————————–

    get_userdata()
    Defined at: * /wp-includes/pluggable.php -> line 113

    /**
     * Retrieve user info by user ID.
     *
     * @since 0.71
     *
     * @param int $user_id User ID
     * @return bool|object False on failure, User DB row object
     */
    function get_userdata( $user_id ) {
    	global $wpdb;
    
    	$user_id = absint($user_id);
    	if ( $user_id == 0 )
    		return false;
    
    	$user = wp_cache_get($user_id, 'users');
    
    	if ( $user )
    		return $user;
    
    	if ( !$user = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->users WHERE ID = %d LIMIT 1 ORDER BY $wpdb->business_name ASC", $user_id)) )
    		return false;
    
    	_fill_user($user);
    
    	return $user;
    }
    endif;
    
    if ( !function_exists('update_user_cache') ) :
    /**
     * Updates a users cache when overridden by a plugin.
     *
     * Core function does nothing.
     *
     * @since 1.5
     *
     * @return bool Only returns true
     */
    function update_user_cache() {
    	return true;
    }
    endif;

    ————————————————–

    get_row()
    Defined at: * /wp-includes/wp-db.php -> line 723

    /**
    	 * Retrieve one row from the database.
    	 *
    	 * @since 0.71
    	 *
    	 * @param string $query SQL query
    	 * @param string $output ARRAY_A | ARRAY_N | OBJECT
    	 * @param int $y Row num to return
    	 * @return mixed Database query results
    	 */
    	function get_row($query = null, $output = OBJECT, $y = 0) {
    		$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
    		if ( $query )
    			$this->query($query);
    		else
    			return null;
    
    		if ( !isset($this->last_result[$y]) )
    			return null;
    
    		if ( $output == OBJECT ) {
    			return $this->last_result[$y] ? $this->last_result[$y] : null;
    		} elseif ( $output == ARRAY_A ) {
    			return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null;
    		} elseif ( $output == ARRAY_N ) {
    			return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null;
    		} else {
    			$this->print_error(/*WP_I18N_DB_GETROW_ERROR*/" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"/*/WP_I18N_DB_GETROW_ERROR*/);
    		}
    	}

    Thread Starter skozyk

    (@skozyk)

    Simply put, I’d like to know how to display Register Plus data in alphabetical order by the users last name.

    Thank you.

    Hey there Skozyk, I am trying to do the same thing.

    So from what you have shown above, do I simply need to cut and paste the three code snippets into my matching files to get my register plus meta data to display?

    This has been vexing me for quite some time.

    Thanks in advance for your reply !

    I have meta_key fields like : first_name , last_name, age, things like that.

    Cheers

    I’ve been looking something like this for my Capoeira Website since we are having our most important workshop at August and we may need the participants to register and submit data using Register Plus and then print and use all those data for administrative purposes.

    I’ll study this deeply to get what we need.

    Thanks.

    Our website if you want to see:

    https://longedomar.com

    ?Axe!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Displaying Register Plus Data’ is closed to new replies.