Support

Account

Home Forums Front-end Issues Add a link to the user profile page (using user field)

Helping

Add a link to the user profile page (using user field)

  • Hello,

    for our site we built a co-author field that lists all users on the website.
    In the backend it is clickable so that the co authors of articles can be selected.

    They are in turn presented on the frontend using the code below.

    We would like to add the link to the user profile page in the ‘display name’, so that when the author’s name is clicked one gets to see his profile page.

    We are, however, stuck on how to achieve this using the formula below.

    Any help would be greatly appreciated.

    <div id="meta-coauthor"><span class='metacoauteur'><?php $values = get_field('coauteurs'); if($values) { foreach($values as $value) { echo ', ' . $value['display_name'] . '';} };?></span></div>

  • Hi Nessler, sorry for the late reply.

    Tell me if it works for you

    
    <div id="meta-coauthor">
    	<span class='metacoauteur'>
    	<?php 
    		$values = get_field('coauteurs'); 
    		if($values) { 
    			foreach($values as $value)	{
    				$author_ID = $value['ID'];
    				$author_url = esc_url( get_author_posts_url($author_ID) );
    
    				echo ', <a href="'.$author_url.'">' . $value['display_name'] . '</a>';
    			}	
    		};
    	?>
    	</span>
    </div>
    
    
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Add a link to the user profile page (using user field)’ is closed to new replies.