[英]How do I get Post Object data form Wordpress ACF - Flexible Content field
Using Advanced custom field plugin I have a custom post type that has various custom fields assigned to it. 使用高级自定义字段插件,我有一个自定义帖子类型,已为其分配了各种自定义字段。
I'm trying to output all of the data that is contained in the flexible content field "content" 我正在尝试输出包含在灵活内容字段“内容”中的所有数据
I have it outputting "text_ad" ok but for some reason i can't figure our the "newsletter_article" which is a post object - Any direction to getting this working would be amazing. 我可以输出“ text_ad”,但是出于某种原因,我无法弄清楚我们的“ newsletter_article”是一个发布对象-任何实现此工作的方向都将是惊人的。
Read this https://www.advancedcustomfields.com/resources/flexible-content/ and this https://www.advancedcustomfields.com/resources/post-object/ 阅读此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;
?>
Because I'am just getting one object I can access the data like this. 因为我只是得到一个对象,所以我可以像这样访问数据。
<?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.