【发布时间】:2015-09-01 05:02:52
【问题描述】:
我在 Wordpress 中有一个名为 People 的自定义帖子类型(people 中的每个帖子都是一个带有一些个人简介等的人)。
在每个 People 帖子中,我创建了一个名为“标签”的自定义字段,其中包含一系列复选框。
如果有人点击系统管理器复选框,我希望能够只拉出特定页面上的所有系统管理器。
我取得的最大成功是使用 wp_get_recent_posts 而不是新的 wp_query .. 这将输出所有人,直到我添加额外的元查询搜索。然后什么都没有出现。
$people_args = array(
'post_type' => 'people',
'post_status'=>'publish',
'meta_query' => array(
array(
'key' => 'tags', // name of custom field
'value' => 'systemmanager',
'compare' => 'LIKE'
)
)
);
$people_posts = wp_get_recent_posts($people_args);
foreach( $people_posts as $people ){
$fields = get_fields($people["ID"]);
if (get_post_thumbnail_id( $people["ID"] )>0) {
$myimgsp = wp_get_attachment_image_src(get_post_thumbnail_id($people["ID"]),'full');
echo '
<li class="item">
<a href="'.get_permalink(43).'"><img src="'.$myimgsp[0].'" alt="'.$people["post_title"].'" class="img-responsive" /></a>
<div class="profile">
<h3>'.$people["post_title"].'</h3>
<p>'.$fields["job_title"].'</p>
<a href="'.get_permalink(43).'" class="btn invert black">View Profile</a>
</div>
</li>';
}
}
wp_reset_query();
我已经坚持了几个小时尝试所有不同类型的循环,但我没有运气。有没有人遇到过这个问题?
【问题讨论】:
标签: php wordpress tags custom-post-type