粗略的方法是设置balance
到\'mt1.meta_value\'
然后使用\'posts_request\'
筛选以删除转义引号:
$args = array(
\'post_type\' => \'post\', // maybe not
\'meta_query\' => array(
array(
\'key\' => \'balance\',
\'compare\' => \'>=\',
\'value\' => \'mt1.meta_value\', // this will be treated as a string
\'type\' => \'NUMERIC\'
),
// this is to force adding the needed JOIN clause
array(
\'key\' => \'monthly_price\',
\'compare\' => \'EXISTS\'
),
\'relation\' => \'AND\'
)
);
$closure = function( $sql ) {
// remove single quotes around \'mt1.meta_value\'
return str_replace( "\'mt1.meta_value\'", "mt1.meta_value", $sql );
};
add_filter( \'posts_request\', $closure );
$query = new \\WP_Query( $args ); // this is your query :)
remove_filter( \'posts_request\', spl_object_hash( $closure ) );
我应该补充一下
\'mt1.meta_value\'
因为WordPress在参数中有多个元查询时会使用如下表别名
"mt{$n}"
哪里
$n
对于每个附加查询,都会递增。