Displaying a list of users and their submitted data

Home Forums User Registration Displaying a list of users and their submitted data

This topic contains 8 replies, has 2 voices, and was last updated by  rumesh38 6 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #18777

    Mike Berg
    Participant

    I have the following code to generate a table of all users of a specific role. What code can I use to display images they’ve uploaded, and text they’ve submitted using the User Registration form?

    <h3>Workshop Leaders</h3>
    <table class="workshopleaders">
        <tr>
    	    <td>
    		    First
    	    </td>
    	    <td>
    		    Last
    	    </td>
    	    <td>
    		    Headshot
    	    </td>
    	    <td>
    		    Bio
    	    </td>
        </tr>
        
        <?php
    	    $args = array(
    		    'role'         => 'workshop_leader_applicant_2019',
    		    'orderby'      => 'nicename',
    	    );
    	    $blogusers = get_users( $args );
    	    foreach ($blogusers as $user) { 
    	    ?>
    	    
    
    	    	 <tr>
    			    <td>
    				    <a href="mailto:<?php echo $user->user_email; ?>"><?php echo $user->first_name ?>
    			    </td>
    			    <td>
    				    <?php echo $user->last_name ?>
    			    </td>
    			    <td class="headshot">
    				    Headshot <!-- THIS IS WHERE I WANT TO SHOW AN UPLOADED IMAGE -->
    			    </td>
    			    <td>
    				    Bio <!-- THIS IS WHERE I WANT TO SHOW SOME SUBMITTED TEXT -->
    			    </td>
    		    </tr>
    	        
    	<?php } ?>
        
    </table>
    

    Thanks!

    #18779

    rumesh38
    Moderator

    Hi Mike,

    User’s data from our registration form’s are all stored in the User Meta table. You can use the following code to get meta data of users.

    get_user_meta( $user->ID, 'user_registration_< Field Name >', true );

    Example:
    $bio = get_user_meta( $user->ID, 'user_registration_description', true );

    Hope this helps! Let us know if you have any confusions.

    Thanks & Regards,
    WPEverest Support Team.

    #18799

    Mike Berg
    Participant

    Thanks! I’ve got it working now. For the bio, I realized that it was using the default WP “description” field for it, so once I removed ‘user_registration_’ from the field name, it worked, like so:

    <?php 
     $bio = get_user_meta( $user->ID, 'description', true );
     echo $bio; 
    ?>

    If anyone else finds this post, here’s the code I used to get an uploaded image to display:

    <?php 
        $attachment_id = get_user_meta( $user->ID, 'user_registration_file_1551057795', true );
    	$size = 'thumbnail';
    	$image = wp_get_attachment_image_src( $attachment_id, $size );
    ?>
    <img src="<?php echo $image[0]; ?>" />
    #19164

    Mike Berg
    Participant

    Ok I have another question on this topic. What is the exact PHP for displaying a series of checkboxes? When I follow the above steps, it just outputs “Array”.

    I’ve tried this, but it’s not right. What have I got wrong, here?

    <?php 
        $shiftchoices = get_user_meta( $user->ID, 'user_registration_check_box_1548908196', true );
        foreach($shiftchoices as $shiftchoice){
    	    echo $shiftchoice;
    	    echo '<br />'; 
        }
    ?>

    Thanks!

    #19186

    rumesh38
    Moderator

    Hi Mike,

    The above code should be working fine! Can you show us your full code for this page? I think the issue might be $user is not defined in your code. And also please check if the user is assigned to the correct registration form where your checkbox field is added.

    Thanks & Regards,
    WPEverest Support Team.

    #19237

    Mike Berg
    Participant

    This is the error that’s showing on the page:

    Warning: Invalid argument supplied for foreach() in <file path and line number>

    Here’s the full code:

    <?php
        $args = array(
    	    'role'         => 'volunteer_applicant_2019',
    	    'orderby'      => 'nicename',
        );
        $blogusers = get_users( $args );
        foreach ($blogusers as $user) { 
    ?>
        
    
    	 <tr>
    	    <td>
    		    <a href="mailto:<?php echo $user->user_email; ?>"><?php echo $user->first_name ?>
    	    </td>
    	    <td>
    		    <a href="https://homesteaderfest.ca/wp-admin/user-edit.php?user_id=<?php echo $user->ID; ?>" target="_blank"><?php echo $user->last_name ?></a>
    	    </td>
    	    <td class="phone">
    		    <?php 
    			    $phone = get_user_meta( $user->ID, 'user_registration_phone_1548907243', true );
    			    echo $phone; 
    			?>
    	    </td>
    	   
    	    <td class="coord_vol">
    			<?php 
    			    $coord = get_user_meta( $user->ID, 'user_registration_radio_1549031297', true );
    			    echo $coord; 
    			?>
    	    </td>
    	    <td class="shift">
    			<?php 
    			    $shiftchoices = get_user_meta( $user->ID, 'user_registration_check_box_1548908196', true );
    			    foreach($shiftchoices as $shiftchoice){
    				    echo $shiftchoice;
    				    echo '<br />'; 
    			    }
    			?>
    	    </td>
    	    <td class="first_choice">
    		    <?php 
    			    $coord = get_user_meta( $user->ID, 'user_registration_select_1548908371', true );
    			    echo $coord; 
    			?>
    	    </td>
    	    <td class="second_choice">
    		    <?php 
    			    $coord = get_user_meta( $user->ID, 'user_registration_select_1548908498760', true );
    			    echo $coord; 
    			?>
    	    </td>
    	    <td class="third_choice">
    		    <?php 
    			    $coord = get_user_meta( $user->ID, 'user_registration_select_1548908551352', true );
    			    echo $coord; 
    			?>
    	    </td>
        </tr>
        
    <?php } ?>
    #19238

    Mike Berg
    Participant

    Note that all the other fields are echoing the correct info, so the $user is definitely correct.

    #19239

    Mike Berg
    Participant

    Oh sheesh, I figured it out. Some of those fields were empty. I solved the problem by checking to see if the array was empty or not. It’s working with this code:

    <?php 
        $shiftchoices = get_user_meta( $user->ID, 'user_registration_check_box_1548908196', true );
        if($shiftchoices){
    	    foreach($shiftchoices as $shiftchoice){
    		    echo $shiftchoice;
    		    echo '<br />'; 
    	    }
        }
    ?>
    #19272

    rumesh38
    Moderator

    Glad to hear that!
    If you have a moment to spare then we would really appreciate your review for our plugin https://wordpress.org/support/plugin/user-registration/reviews/?filter=5

    Thanks & Regards,
    WPEverest Support Team.

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.