Home › Forums › ACF PRO › Retrieve data from post-object them the post has been created with ACF comp. › Reply To: Retrieve data from post-object them the post has been created with ACF comp.
Hi, thanks for the response but or I don’t understand it, or my case is a lit bit diverse that I’d describe for you.
I try to use
$value = get_field('field_name', $news->ID);
directly in the flexible content template tag but it doesn’t work. See it:
<div class="news-group"> <?php if( have_rows('news_home_list') ): while ( have_rows('news_home_list') ) : the_row(); if( get_row_layout() == 'news_home_list_plus' ): $news = get_sub_field('news_home_select'); $title = get_the_title($news->ID); $abstract = get_field('news_abstract', $news->ID); ?> <div class="news"> <strong><?php $title; ?></strong> <p><?php $abstract; ?></p> </div> <?php endif; ?> <?php endwhile; ?> <?php endif; ?> </div>
I try to use setup_postdata() doc example but nothing, 🙁
<div class=”news-group”> <?php if( have_rows(‘news_home_list’) ): while ( have_rows(‘news_home_list’) ) : the_row(); if( get_row_layout() == ‘news_home_list_plus’ ): $news = get_sub_field(‘news_home_select’); $featured_posts = get_field(‘news_home_select’); if( $featured_posts ): ?> <?php foreach( $featured_posts as $post ): // Setup this post for WP functions (variable must be named $post). setup_postdata($post); ?> <div class=”news”> <div class=”news-content”> <a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a> <span>A custom field from this post: <?php the_field( ‘news_abstract’ ); ?></span> </div> <?php endforeach; ?> <?php // Reset the global post object so that the rest of the page works correctly. wp_reset_postdata(); ?> </div> <?php endif; ?> <?php endif; ?> <?php endwhile; ?> <?php endif; ?> </div>
I remember that my post object is into flexible content…
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!
We’re hard at work on ACF 6.1, and Beta 1 is now available 🚀— Advanced Custom Fields (@wp_acf) March 16, 2023
This release includes custom post type and taxonomy registration, an improved experience when selecting field types, PHP 8.1 and 8.2 compatibility, and more!
Let’s take a look 🧵https://t.co/Y0WcAT11l4
© 2023 Advanced Custom Fields.