【发布时间】:2019-08-31 05:18:52
【问题描述】:
我有两种自定义帖子类型:员工和位置。在员工的 CPT 中,我使用 ACF 关系字段选择相应的位置。
在前端,我正在显示一个位置并列出该位置的所有工作人员。然而,我的问题是我无法让所有工作人员都出席。最多只能显示 5 个。
我目前在一个地点分配了 7 名员工。前端仅显示 5 个。如果我删除正在显示的 5 个中的一个,则另一个将取而代之。
'''
<?php while ( have_posts() ) : the_post(); ?>
<?php
/*
* Query posts for a relationship value.
* This method uses the meta_query LIKE to match the string "123" to the database value a:1:{i:0;s:3:"123";} (serialized array)
*/
$staff = get_posts(array(
'post_type' => 'people',
'meta_query' => array(
array(
'key' => 'location', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exactly "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
));
?>
<div class="people-grid">
<?php if( $staff ): ?>
<?php foreach( $staff as $doctor ): ?>
<?php
$photo = get_field('photo', $doctor->ID);
?>
<div class="single-person">
<img src="<?php echo $photo['url']; ?>" alt="<?php echo $photo['alt']; ?>" />
<h3><?php echo get_the_title( $doctor->ID ); ?></h3>
<h4><?php echo get_field('position_title', $doctor->ID); ?></h3>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php endwhile; // end of the loop. ?>'''
我希望这个页面有 7 个成员,但我只能看到 5 个:https://aptw.nk-creative.com/locations/goshen-ny/
【问题讨论】:
标签: wordpress advanced-custom-fields custom-post-type