php - Wordpress Advanced Custom Fields display field not working in loop -


i using advanced custom fields wordpress. have custom post type called videos has 2 fields - video_link , video_artist.

i can call , output video_link field, cannot seem display 'video_artist' field using code below...

<?php     $posts = get_posts(array(    'post_type'          => 'videos',    'posts_per_page'     => -1    )    ));                      if( $posts ): ?> <?php foreach( $posts $post ):     setup_postdata( $post )                      ?> <?php echo wp_oembed_get( get_field( 'video_link' ) ); ?> <?php the_title(); ?> <?php the_field('video_artist'); ?> </div> <?php endforeach; ?> <?php wp_reset_postdata(); ?> <?php endif; ?> 

in fact, line...

<?php the_field('video_artist'); ?> 

...breaks site , displays nothing @ after appears. no html of kind.

it's more or less same code your, tested, , works fine

as @admcfadn said, note in wordpress loop, need add post id parameter of the_field

$posts = get_posts(array(     'post_type'          => 'videos',     'posts_per_page'     => -1 ));          if( $posts ):       foreach( $posts $post ):          setup_postdata( $post );                          the_title();           the_field('video_link', $post->id);          the_field('video_artist', $post->id);       endforeach;      wp_reset_postdata();  endif;  

if use loop without arg in the_field that:

$options = array(     'post_type'          => 'videos',     'posts_per_page'     => -1 );  $query = new wp_query( $options );  if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();       the_title();       the_field('video_link');      the_field('video_artist');  endwhile; endif; 

ps: don't need use <?php ?> on each line


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -