I am trying to create a custom author block on my wordpress website. The website is build on elementor. With the use of ACF I created a relationship (our_people_author) between the blog posts and custom post type (our people) – which contains posts presenting people.
I would like to add this code to functions.php or turn it into a shortcode but I am getting an error. Would anyone be able to help me with it?
$authors = get_field('our_people_author');
<?php foreach($authors as $author):?>
<img src="<?php echo get_the_post_thumbnail_url($author->ID, 'thumbnail');?>">
<h3>
<a href="<?php echo get_page_link($author->ID);?>">
<?php echo $author->post_title;?>
</a>
</h3>
<?php endforeach;?>
2
Answers
You are missing this
setup_postdata( $author );
Assuming that you are using the shortcode on the same page/post/custom_post where you have the custom field "our_people_author" saved.
Just add the following code in your function file.
Make sure to replace YOUR_SHORTCODE_NAME with your shortcode name.
Also I have noticed that you have added <?php tag in wrong place in your code line no 2.