排除具有特定自定义域和值的帖子

时间:2019-10-28 作者:bpy

如何在此查询中排除具有特定自定义字段和值的帖子?

$my_query = new WP_Query(  $args = array(
        // It should be in the first category of our post:
        \'category__in\' => array( $st_cat ),
        // Our post should NOT be in the list:
        \'post__not_in\' => array( $post->ID ),
        \'posts_per_page\' => 8,
        \'orderby\' => \'desc\',
    ));

I already tried this without sucess:

$my_query = new WP_Query(  $args = array(
        // It should be in the first category of our post:
        \'category__in\' => array( $st_cat ),
        // Our post should NOT be in the list:
        \'post__not_in\' => array( $post->ID ),
        \'posts_per_page\' => 8,
        \'orderby\' => \'desc\',
         //extra code added without sucess
        \'meta_query\' => array(
        \'key\' => \'city\',
        \'value\' => \'true\',
        \'compare\' => \'NOT LIKE\',
    )
));

2 个回复
SO网友:user10758246

meta\\u query参数接受一个数组。

\'meta_query\' => array(
    array(
        \'key\' => \'city\',
        \'value\' => \'true\',
        \'compare\' => \'NOT LIKE\',
    )
)

SO网友:bpy

也许这样的方法可以奏效:

     if ( !$query->is_admin && $query->is_search) {
     $query->set(\'post__not_in\', array(36,33));
     $query->set(\'meta_query\',
     array(\'relation\' => \'OR\',
        array(\'key\' => \'city\',
              \'value\' => \'true\', 
              \'compare\' => \'NOT EXISTS\'),
    ));
 }
 return $query;

相关推荐

如何在wp-Query中比较不同的时间戳以获取事件自定义帖子类型?

我有一个带有自定义元数据库的自定义帖子类型(as seen on wptheming.com) 并且希望进行查询以显示即将发生的事件,例如在侧边栏中,过去的日期被忽略。但我需要一个当前时间的值来和事件开始时间进行比较。现在我从current_time(\'mysql\') 看起来是这样的:2012-02-16 13:15:31元的开始时间如下所示:201108121100如何使这两个日期具有可比性?我可以在查询中执行吗?或者是否有其他解决方案?以下是我到目前为止的查询(值留空,时间戳回显):<?ph