php - 为 Wordpress 的高级自定义字段 (ACF) 中的组字段编写 meta_query
问题描述
我认为 ACF 文档在如何查询使用高级自定义字段创建的组的子字段方面非常稀疏。
例子:
acf_custom_dates_group acf_custom_date_group_child
如何对子字段中的值执行 meta_query?
解决方案
这里的诀窍是结合组和子字段键名。我相信 LIKE 运算符也是必要的。
/*
The name of my custom group: acf_custom_dates_group
The name of my sub field: acf_custom_date_group_child
Name combined as 'key' and separated by underscore (see below)
*/
$format_value = ''; // set by ajax
$myquery = new WP_Query([
'posts_per_page' => -1,
'post_type' => 'posts',
'meta_query' => [
//'relation' => 'OR',
//'relation' => 'AND',
[
'key' => 'acf_custom_dates_group_acf_custom_date_group_child',
'compare' => 'LIKE',
'value' => $format_value
],
],
]);
推荐阅读
- python - 在 Idle (Python 3.7.4) 中输入 import nltk 后,我得到一个 ModuleNotFoundError: No module named "nltk"
- airflow - iam.gserviceaccount.com 没有 storage.buckets.get 访问权限
- git - “发生错误。详细消息:1 个未提交的更改将被合并覆盖”
- visual-studio - 如何更改应用程序主页面标题中文本的大小和样式?
- python - 如何将关键字参数传递给 pre-forward 钩子使用的 forward?
- azure-active-directory - Azure AD 属性 user.assignedroles 未在 SAML 响应中发送,null
- powershell - 公共专用域设置,-允许应用程序通过 Windows 防火墙,-为此,Windows 10 中可用的最佳 powershell cmdlet 是什么
- sql-server - 将粘贴问题从 ssms 2012 复制到 Excel
- reactjs - 用 state 初始化 redux 表单控件到 props
- python - 如何在底图图中的栅格字段周围绘制线边框?