【发布时间】:2018-09-24 06:27:09
【问题描述】:
所以我有一个客户,他的员工会获得评论。客户希望他们的简历页面与他们的评论页面分开。我有一个用于简历和评论的页面模板。
每份推荐书都有一个 ACF 关系字段,客户可以在其中选择评价对象的简历。这些评论将由客户手动输入,因为它们特定于他们自己的客户。
如何获取分配给特定人员的评论,然后将它们显示在该人单独的评论页面上。
我试过这个,它给了我一个数组,但遗憾的是这是我输入的每个测试评论,而不仅仅是分配给特定人员的两个
<?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)
*/
$subject = the_field('testimonial_broker', $post->ID);
$testimonials = get_posts(array(
'post_type' => 'testimonial',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'testimonial_broker',
'value' => $subject,
'compare' => 'LIKE',
)
)
));
var_dump($testimonials);
?>
<?php if( $testimonials ): ?>
<?php foreach( $testimonials as $testimonial ): ?>
<?php
$photo = get_field('testimonial_logo', $testimonial->ID);
$testimonial_text = get_field('testimonial_body', $testimonial->ID);
var_dump($photo);
var_dump($testimonial_text);
?>
<div class="row testimonial align-items-center">
<div class="col-lg-3">
</div>
<div class="col-lg-9 bg-offwhite">
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
【问题讨论】:
标签: wordpress foreach relationship advanced-custom-fields