wordpress - Wordpress - 获取具有特定 ACF 值的帖子
问题描述
我有一个使用 FacetWP 插件和高级自定义字段为帖子制作额外字段的网站。
每个帖子都可以有一个“部门”值,我需要为不同的部门创建一个 foreach,如下所示:
if ($department == "Office") {
get all the post with the Value Office from the ACF field "department."
}
自定义字段是一个选择/下拉字段。
我也需要为“生产”、“老板”、“饮料”等其他部门做同样的事情。但是我需要给部门一个标题,下面有结果。
做这个的最好方式是什么?
问候,
更新:
最后我需要的是在概述的一页上:
职位:办公室 - 员工 1 - 员工 2 - 员工 3 - 员工 4
标题:生产 - 员工 1 - 员工 2 - 员工 3
职位:老板 - 员工 1
解决方案
在这种情况下,自定义字段“位置”可以是文本字段、单选按钮或选择字段(保存单个文本值的东西)。
<?php
$location = get_field('location');
// args
$args = array(
'posts_per_page' => -1,
'post_type' => 'event',
'meta_key' => 'location',
'meta_value' => $location
);
// query
$the_query = new WP_Query( $args );
?>
<?php if( $the_query->have_posts() ): ?>
<h1> <?php echo $location ?> </h1>
<ul>
<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<img src="<?php the_field('event_thumbnail'); ?>" />
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
推荐阅读
- themes - Shopify 主题许可证
- c# - Web 应用程序中的 Newtonsoft.Json 6.0.0.0 和 12.0.0.0 与 Web Api、C# 冲突
- android - 如何在 Android Studio 中添加平板电脑分辨率支持
- swagger - 在 Nest.js 项目中添加 Swagger 基本路径字段
- mysql - 在mysql中选择多个表的公共值
- .net - 您可以从常规 .net 应用程序中使用 Roslyn 编译器吗?
- python - 使用 Socket 网络后端创建 QEMU 桥接器
- sql - 将多个 SQL Server 表合并为一个
- machine-learning - 如果我添加一个新特性,xgboost 参数会不会要改变?
- android - 会话结束时删除图像和 pdf