Wordpress meta_query compare not in issue

2019-08-05 06:26发布

I have a issue with wordpress meta query.

I make a checkbox in meta box, When user check the check box the post is become featured. Now I call all posts except featured, but I don't get it.

Here is my code:

$wa_story_args = array(
                'post_type' => 'stories',
                'posts_per_page' => 999,
                'orderby' => 'DESC',
                'meta_query' => array(
                    array(
                    'meta_key' => 'wa_featured_story',
                    'meta_value' => 'featured',
                    'compare' => 'NOT IN'
                        )
                )
            );

2条回答
做个烂人
2楼-- · 2019-08-05 07:08

Just replace "meta_value" by "value" and "meta_key" by "key":

$wa_story_args = array(
            // ...
            'meta_query' => array(
                array(
                'key' => 'wa_featured_story',
                'value' => 'featured',
                'compare' => 'NOT IN'
                    )
            )
        );
查看更多
来,给爷笑一个
3楼-- · 2019-08-05 07:24

Try using the '!=' operator instead of 'NOT IN' as this is usually used to check against arrays.

You should also consider adding a OR 'NOT EXISTS' condition.

查看更多
登录 后发表回答