![](/img/trans.png)
[英]Retrieve meta field values of ACF flexible content items using get_post_meta - WordPress
[英]How do I get Post Object data form Wordpress ACF - Flexible Content field
使用高級自定義字段插件,我有一個自定義帖子類型,已為其分配了各種自定義字段。
我正在嘗試輸出包含在靈活內容字段“內容”中的所有數據
我可以輸出“ text_ad”,但是出於某種原因,我無法弄清楚我們的“ newsletter_article”是一個發布對象-任何實現此工作的方向都將是驚人的。
閱讀此https://www.advancedcustomfields.com/resources/flexible-content/和此https://www.advancedcustomfields.com/resources/post-object/
<?php
// check if the flexible content field has rows of data
if( have_rows('content') ):
// loop through the rows of data
while ( have_rows('content') ) : the_row();
if( get_row_layout() == 'text_ad' ):
echo the_sub_field('text_ad_title');
echo the_sub_field('text_ad_url');
echo the_sub_field('text_ad_description');
elseif( get_row_layout() == 'newsletter_article' ):
$post_object = get_sub_field('the_newsletter_article');
if( $post_object ):
$post = $post_object;
setup_postdata( $post );?>
<strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></strong>
<?php
wp_reset_postdata();
endif;
endif;
endwhile;
else :
// no layouts found
endif;
?>
因為我只是得到一個對象,所以我可以像這樣訪問數據。
<?php
elseif( get_row_layout() == 'newsletter_article' ):
$post_object = get_sub_field('the_newsletter_article');
$newstitle = $post_object->post_title;
$newsdescription = $post_object->post_content;
?>
<div style="background-color: #cccccc; margin:0 0 20px 0;">
<p><strong><?php echo $newstitle; ?></strong></p>
<p><?php echo $newsdescription; ?></p>
</div>
<?php endif; ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.