如何在此查询中排除具有特定自定义字段和值的帖子?
$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\',
)
));
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;