Support

Account

Home Forums General Issues Get the author meta dynamically

Unread

Get the author meta dynamically

  • In my template I have a function, which gets all the users of the WordPress installation in order to display them on the frontend.

    In addition, I made a custom field so that only users appear, who have checked this custom radio button.

    This is my code:

    <div class="col">
    
        <?php
        
            // Get all users. you can use the WodPress args to filter them.
            $blogusers = get_users( 'blog_id=1&orderby=nicename' );
            // Array of WP_User objects.
            foreach ( $blogusers as $user ) { 
            // Creating the var user_ID to use with ACF Pro
            $user_id = 'user_'. esc_html( $user->ID );
            ?>
    
            <?php if( get_field('display_on_team', $user_id) ): ?>
    
                <div class="col-4">
        
                    <?php echo get_avatar( $user->id, '300' ); ?>
                    
                    <?php
                    if ( isset( $_GET['author_name'] ) ) {
                        $curauth = get_user_by( 'slug', $author_name );
                    } else {
                        $curauth = get_userdata( intval( $author ) );
                    }
                    ?>
                    <h3><?php echo esc_html( $user->display_name ); ?></h3>
                    
                </div>
    
            <?php else: ?>
            
            <?php endif; ?>          
            
        <?php } ?>
    
    </div>
    
    <div class="col">  
            <!-- Display the user-description of the selected user -->
            <p><?php echo $user->user_description; ?></p>
    </div>

    This is working as intended.

    Now I need to extend this function (in the bottom of the code):

    If you click on the avatar of an author, I need to display the associated user_description. In conclusion, the user_description should be dynamically changed depending on the selected avatar.

    Is this possible with PHP and JS? Or do I need Ajax for this?
    Since I’m a beginner, I don’t know how to approach this.

    Thanks for any help!

Viewing 1 post (of 1 total)

The topic ‘Get the author meta dynamically’ is closed to new replies.