Thank you for the example link. Would I use Display list of posts (without setup_postdata) below?
I am not sure what exactly is setup_postdata?
<?php $featured_posts = get_field('featured_posts'); if( $featured_posts ): ?> <ul> <?php foreach( $featured_posts as $featured_post ): $permalink = get_permalink( $featured_post->ID ); $title = get_the_title( $featured_post->ID ); $custom_field = get_field( 'field_name', $featured_post->ID ); ?> <li> <a href="<?php echo esc_url( $permalink ); ?>"><?php echo esc_html( $title ); ?></a> <span>A custom field from this post: <?php echo esc_html( $custom_field ); ?></span> </li> <?php endforeach; ?> </ul> <?php endif; ?>
Since my Custom field is related_posts would I just change the below?
$custom_field = get_field( 'field_name', $featured_post->ID );
$custom_field = get_field( 'related_posts', $featured_post->ID );
How can I add this all as a shortcode? I use code snippets plugin so I can create a snippet to add the whole. How can I put text before ” Related Posts:” What if there are no related posts will it return nothing?
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!