【问题标题】:Wordpress How to get ACF relationship with WP_QueryWordpress 如何使用 WP_Query 获取 ACF 关系
【发布时间】:2021-05-06 10:41:07
【问题描述】:

在我的Wordpress 应用程序中,我有一个名为“departments”的自定义字段,其中有一个名为“department_customer”的关系字段 - 它应该返回部门分配给的客户。我试图这样做:

$departments = new WP_Query([
   'post_type' => 'department',
   'posts_per_page' => -1,
   'meta_query' => [
     [
       'key' => 'department_customer',
       'value' => (int) $post->ID,
       'type' => 'NUMERIC',
       'compare' => '='
     ]
  ],
]);

然后循环遍历:

foreach($departments->posts as $department){
    echo $department; // just for testing if something returns
}

但这什么都没有返回...我做错了什么?

【问题讨论】:

标签: php wordpress advanced-custom-fields


【解决方案1】:

也许这个文档可以帮助你:

https://www.advancedcustomfields.com/resources/querying-relationship-fields/

也许你可以试试这样的:

'meta_query' => array(
  array(
    'key' => 'department_customer',
    'value' => '"' . get_the_ID() . '"',
    'compare' => 'LIKE'
  )
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-21
    • 2020-07-03
    • 1970-01-01
    • 2019-03-13
    • 2018-01-28
    • 2017-06-20
    • 2020-10-08
    • 1970-01-01
    相关资源
    最近更新 更多