wp meta_query将在meta_filed乘以时获得没有特定值的帖子
找不到一个解决方案如何查询帖子,而没有某些具有许多值的元field值的特定值。
情况是: 当用户执行某些特定操作时,我将在帖子上添加ID。像这样:add_post_meta($ _ post ['post_id'],'users_touched_ids',$ current_user_user-> id);
之后,我必须向他展示并没有被他“触摸过”的用户帖子显示。因此,我正在编写这样的查询:
[
'relation' => 'OR',
[
'key' => 'users_touched_ids',
'compare' => '!=',
'value' => $user_id
],
[
'key' => 'users_touched_ids',
'compare' => 'NOT EXISTS',
],
]
但是它不起作用。我得到所有帖子=(
Can't find a solution how to query posts without some specific value of meta_field that have many values.
The situation is:
I'm adding user id's on posts when they perform some specific operation. Like this: add_post_meta($_POST['post_id'], 'users_touched_ids', $current_user->ID);
After that I have to display to user posts that wasn't "touched" by him. So I'm writing query like this:
[
'relation' => 'OR',
[
'key' => 'users_touched_ids',
'compare' => '!=',
'value' => $user_id
],
[
'key' => 'users_touched_ids',
'compare' => 'NOT EXISTS',
],
]
But it doesn't work. I'm getting all posts =(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您会收到所有帖子,当查询帖子
users_touched_ids
不等于$ user_id
。这意味着,您将获得所有帖子,其中数据库字段users_touched_ids
不包含$ user_id
varable。如果作者与“触摸”用户相同,则可以按照作者过滤查询:
You getting all posts, while you query posts where
users_touched_ids
not equals to$user_id
. This means, you get all posts where the database fieldusers_touched_ids
not contains the$user_id
variable.in case, the Author is the same as the "touch" user, you can filter the query by author like this: