简体   繁体   English

获取除特定帖子元之外的所有帖子

[英]Get all posts except with specific post meta

So I have the following conditional:所以我有以下条件:

$args = [
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 50,
    'paged' => $page,
    'orderby' => 'date',
    'order' => 'desc',
    'meta_query' => [
        [
            'key' => 'global_post',
            'compare' => '!=',
        ]
    ],
];
$query = new WP_Query($args);

I have some posts that have the post_meta as 'global_post' - I want to be able to pull ALL posts except posts that have that specific post_meta.我有一些帖子将post_meta设为“global_post”——我希望能够提取除具有该特定 post_meta 的帖子之外的所有帖子。

With the above code, I keep getting an empty/null return, even if I have posts with and without that specific post_meta.使用上面的代码,即使我的帖子有和没有那个特定的 post_meta,我也会不断得到一个空的/空的回报。 What am I doing wrong?我究竟做错了什么?

Have you tried NOT EXISTS for the compare ?您是否尝试过NOT EXISTS进行compare Would look like this:看起来像这样:

$args = [
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 50,
    'paged' => $page,
    'orderby' => 'date',
    'order' => 'desc',
    'meta_query' => [
        [
            'key' => 'global_post',
            'compare' => 'NOT EXISTS',
        ]
    ],
];
$query = new WP_Query($args);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM