我试图通过一些自定义字段值过滤自定义帖子类型,如果帖子是按作者,则查询2个自定义字段,但作者帖子不起作用。谢谢
add_filter( \'parse_query\', \'my_admin_posts_filter\' );
function my_admin_posts_filter( $wp_query ) {
if ( strpos( $_SERVER[ \'REQUEST_URI\' ], \'/wp-admin/edit.php?post_type=estate_leads\' ) !== false ) {
if ( !current_user_can( \'level_10\' ) ) {
$current_user = wp_get_current_user();
$author = $current_user -> ID;
$wp_query->set(
\'meta_query\', array(
\'relation\' => \'OR\',
array(
\'key\' => \'leads_status\',
\'value\' => \'-1\',
),
array(
\'key\' => \'leads_status\',
\'compare\' => \'NOT EXISTS\',
),
array(
\'key\' => \'author\',
\'value\' => $author,
)
));
}
} }
SO网友:bgallagh3r
作者键/值查询无法工作。尝试通过将查询移出元查询来修改查询,如下所示:
array(
\'author\' => $author,
\'meta_query\' => array(
\'relation\' => \'OR\',
array(
\'key\' => \'leads_status\',
\'value\' => \'-1\',
),
array(
\'key\' => \'leads_status\',
\'compare\' => \'NOT EXISTS\',
)
)
)