Support

Account

Home Forums General Issues Image field in admin section

Solving

Image field in admin section

  • Hi, i add image field “picture” in section profile of collaborator for let to add personal image for don’t use gravatar.
    I don’t find any solution for display that picture in loop od my landing page where i have collaborator section.
    Can help me for display this snippet?

    This is my code, the problem is in eho adress image..

    <?php
    $args = array (
    ‘role’ => ‘contributor’,
    ‘order’ => ‘ASC’,
    ‘orderby’ => ‘display_name’,

    );

    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($args);

    // Get the results
    $authors = $wp_user_query->get_results();
    $picture = get_field(‘picture’, $post->ID);

    // Check for results
    if (!empty($authors)) {
    echo ‘<div class=”row”>’;
    // loop through each author
    foreach ($authors as $author)
    {
    // get all the user’s data
    $author_info = get_userdata($author->ID);
    echo ‘<div class=”col-md-3″> ‘

    . $author_info->first_name . ‘
    ‘ . $author_info->last_name . ‘<br/>
    ‘ . $author_info->settore . ‘<br/>
    ‘ . $author_info->citta . ‘<br/>
    <br/>

    ‘ . $author_info->cellulare .’ </div>’;

    }
    echo ‘</div>’;
    } else {
    echo ‘No contributor found’;
    }
    ?>

    Thanks very much
    Paolo

  • When getting a field from the user the post ID that you need to supply to ACF is `”user_{$user_id}” See this page for more https://www.advancedcustomfields.com/resources/how-to-get-values-from-a-user/

  • yes..i try this too. but same problem.

    
    <?php
    $args = array (
        'role' => 'contributor',
        'order' => 'ASC',
        'orderby' => 'display_name',
       
       
    );
    
    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($args);
    
    // Get the results
    $authors = $wp_user_query->get_results();
    
    // Check for results
    if (!empty($authors)) {
        echo '<div class="row">';
        // loop through each author
        foreach ($authors as $author)
        {
            // get all the user's data
            $author_info = get_userdata($author->ID);
            $image = get_field('image','user_' . $author->ID);
            echo '<div class="col-md-3"> 
            <ul class="list_detail">	
           <li> '  . $author_info->first_name .  	' 
           '  . $author_info->last_name .  	'</li> 
            <li> '  . $author_info->settore .  		'</li>  
           <li>  '  . $author_info->citta . 			'</li> 
    		<li> <img src="  ' . $image . ' "	/> </li>  
    		
           
           <li>  ' . $author_info->cellulare .' </li> </div>';
            
            
    }
        echo '</div>';
    } else {
        echo 'No authors found';
    }
    ?>
    
  • I resolve with:

    <?php
    $args = array (
        'role' => 'contributor',
        'order' => 'ASC',
        'orderby' => 'display_name',
       
       
    );
    
    // Create the WP_User_Query object
    $wp_user_query = new WP_User_Query($args);
    
    // Get the results
    $authors = $wp_user_query->get_results();
    
    // Check for results
    if (!empty($authors)) {
        echo '<div class="row">';
        // loop through each author
        foreach ($authors as $author)
        {
    	    
    	    
            // get all the user's data
            $author_info = get_userdata($author->ID);
            $image = get_field('image','user_' . $author->ID );
            echo '<div class="col-md-3"> 
            <ul class="list_detail">	
           <li> '  . $author_info->first_name .  	' 
           '  . $author_info->last_name .  	'</li> 
            <li> '  . $author_info->settore .  		'</li>  
           <li>  '  . $author_info->citta . 			'</li> 
    		<li> <img src="' . $image['url'] . '"	/> </li>  
    		
           
           <li>  ' . $author_info->cellulare .' </li> </div>';
            
            
    }
        echo '</div>';
    } else {
        echo 'No authors found';
    }
    ?>
    
Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Image field in admin section’ is closed to new replies.