WordPress WP_User_Query 使用分类法

WordPress WP_User_Query using taxonomy

我最近使用 this tutorial and the ACF taxonomy field, although I didn't see anyway to query on taxonomy based on this 文档将分类法添加到我的用户设置页面我想我会尝试使用这些参数:

$args = [
  'role' => 'gebruiker',
  'number' => $limit,
  'offset' => $offset,
  'tax_query' => array(
    array(
      'taxonomy' => 'category_level',
      'terms' => 36,
      'field' => 'term_id',            
    )
  )
]

但它不起作用,只有 returns 每个匹配其他参数的用户,所以我想知道是否完全可以基于分类法进行查询,如果可以,我该怎么做? :)

虽然我从来没有弄清楚这个问题,但我确实找到了适合我的解决方案 ;)

$args = [
  'key' => 'specialty',
  'value' => '47',
  'compare' => '='
]

WP_User_Query($args);

Returns 只有 2 个用户,这是我的预期,因为只有 2 个用户将 specialty 分类法设置为 ID 为 47 的术语!但是一旦我将此查询包装在 meta_query 标记中(见下文),我就可以添加更多参数,例如用户 role。它将 return 每个匹配 role 查询的用户。

$args = [
  'meta_query' => [
    'key' => 'specialty',
    'value' => '47',
    'compare' => '='
  ]
]

WP_User_Query($args);

所以,我最终做的是编写一个自定义 MySQL 查询来获取必须自定义分类集的用户的 ID,之后我可以使用普通的 WP_Queryrole 参数,我刚刚添加了 include 参数和之前找到的 ID