获取除特定 post 元之外的所有 post

Get all posts except with specific post meta

所以我有以下条件:

$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);

我有一些帖子 post_meta 为 'global_post' - 我希望能够提取所有帖子,除了具有特定 post_meta.

的帖子

使用上面的代码,我不断收到 empty/null return,即使我的帖子有和没有那个特定的 post_meta。我做错了什么?

您是否尝试过 NOT EXISTS compare?看起来像这样:

$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);