Wordpress meta_query compare not in issue

回眸只為那壹抹淺笑 提交于 2020-01-05 08:29:18

问题


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

回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/24934552/wordpress-meta-query-compare-not-in-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!