![](/img/trans.png)
[英]Exclude posts by ID in a custom query built with ACF Gutenberg blocks
[英]Query custom posts filtered by ACF users id
我有一个名为journals
的自定义帖子类型和一个名为editors
的 ACF Users
字段(返回格式 User ID )。
在添加新期刊时,您可以 select 多个用户作为编辑。
现在,我想创建一个查询来获取当前用户被指定为编辑的所有期刊。
我试过这样的事情:
$current_user = wp_get_current_user();
$args = array(
'post_type' => 'journals',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'editors',
'value' => $current_user->ID,
'compare' => 'IN'
)
)
);
我怎样才能做到这一点?
我使用LIKE
而不是IN
如下 -
$current_user = wp_get_current_user();
$args = array(
'post_type' => 'journals',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'editors',
'value' => $current_user->ID,
'compare' => 'LIKE'
)
)
);
这对我有用。
星期天 Lalbiaknia 是正确的。 但在我这边,由于 $current_user->ID 是 integer,因此对此进行了轻微修改,您可以这样做(注意分号):
$current_user = wp_get_current_user();
$args = array(
'post_type' => 'journals',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'editors',
'value' => $current_user->ID . ';',
'compare' => 'LIKE'
)
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.