【发布时间】:2019-10-16 21:58:18
【问题描述】:
下面的一些代码有问题 我使用 wordpress 和插件 ACF PRO。 我查询了一些帖子,在这篇帖子中,它们是一个转发器字段,但它似乎只显示了转发器字段“evenement”的第一行。 不知道是不是很清楚?
有人可以帮助我。
谢谢
<?php $query = new WP_Query(
array(
'category__not_in' => array(520),
'category__and' => array(2905,1582),
'post_status' => array( 'draft'),
'post_type' => 'spectacles',
'lang' => 'fr',
'showposts' => -1,
'meta_key' => 'date_debut',
'orderby' => 'meta_value_num',
'order' => 'ASC')
);?>
<?php if($query->have_posts()) : while ($query->have_posts() ) : $query->the_post();?>
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<div id="bloc-picto">
<div class="item-picto">
<img src="<?php $picto = get_field('picto');if( !empty($picto) ): ?><?php echo $picto['url']; ?><?php else: ?><?php $image_id = get_post_thumbnail_id(); $image_url = wp_get_attachment_image_src($image_id,'icon', true); echo $image_url[0]; ?><?php endif; ?>" width="40px" height="40px">
</div>
<div class="legend-picto">
<b><?php the_title(); ?></b>
<?php if( get_field('compagnie') ): ?>
<?php the_field('compagnie'); ?>
<?php endif; ?>
<br/>
<?php if( get_field('acces_star') ): ?>
<div style="font-size:10px"><?php the_field('acces_star'); ?></div>
<?php endif; ?>
<?php if( have_rows('evenement') ): while ( have_rows('evenement') ) : the_row(); ?>
<?php $post_object = get_sub_field('lieu_evenement');if( $post_object ):
$post = $post_object; setup_postdata( $post ); ?>
<i><?php the_title(); ?></i>
<?php wp_reset_postdata(); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
</a>
<?php wp_reset_postdata(); ?>
<?php endwhile; else: ?>
<?php endif; ?>
【问题讨论】:
-
子字段“lieu_evenement”是什么类型的字段?问题可能来自重置后数据,并且根据您的该子字段的字段类型,可能需要重新处理。实际的中继器代码看起来是正确的,所以我认为它来自设置和重置可能不需要完成的 postdata。
-
子字段“lieu_evenement”是一个帖子对象!你认为是因为这个?
标签: advanced-custom-fields repeater