【发布时间】:2018-05-31 23:48:52
【问题描述】:
我设置了许多灵活的内容字段。
其中一个称为“产品选择器”,另一个称为“产品信息”。
产品选择器使用发布对象功能来拉入选定的产品。
我可以引入默认的 wordpress 部分,例如:
<?php the_post_thumbnail(); ?>
但我无法提取“产品信息”中的值。
这真的可能吗?以下代码摘录:
<?php if( have_rows('content_blocks') ):
while ( have_rows('content_blocks') ) : the_row();
if( get_row_layout() == 'product_information' ):
include("inc/product-information.php");
elseif( get_row_layout() == 'products_picker' ):
include("inc/products-picker.php");
endif;
endwhile;
endif; ?>
然后在“产品选择器”中,我使用以下代码:
<?php foreach( $post_objects as $post): ?>
<?php setup_postdata($post); ?>
<div class="product">
<?php the_post_thumbnail(); ?>
<div class="description">
/* Echoing post ID returns correct value */
<h1><?php echo $post->ID; ?></h1>
/* Does not work */
<h1><?php the_sub_field('heading', $post->ID); ?></h1>
/* Does not work */
<?php the_sub_field('description', $post->ID); ?>
</div> <!-- .description -->
</div> <!-- .product-->
<?php endforeach; ?>
<?php wp_reset_postdata(); ?>
我的内容结构可能有误。
也许您不能在灵活内容中调用灵活内容?
但我认为应该可以这样做,因为默认字段如下:
the_post_thumbnail();
和
the_title();
工作。
非常感谢您的所有时间和帮助。
【问题讨论】:
标签: wordpress advanced-custom-fields