Hi I am struggling to get a subfield for multiple post objects.
The following is my code
<nav id="content-subnav" >
<div class="container">
<?php $post_objects = get_field( 'select_newsletters' ); ?>
<?php if ( $post_objects ): ?>
<?php foreach ( $post_objects as $post ): ?>
<?php setup_postdata( $post ); ?>
<a href="<?php the_sub_field( 'newsletter_link' ); ?>"><?php the_title(); ?></a>
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
</div>
</nav>
I need the sub field newsletter_link but this is not displaying anything
Is newsletter_link
a property of the posts you loaded? Then, instead of the_sub_field( 'newsletter_link' )
, try get_field( 'newsletter_link' , ( $post->ID ?? $post->post_id ?? $post ) )
. Does that spit out what you want it to, or if not, what does it spit out?