我不会说这“简单”,但任何像您所拥有的那样无法通过API处理的复杂查询,WP_Query
, 或其过滤器应使用wpdb class.
global $wpdb;
$rows = $wpdb->get_results(
"
SELECT p1.meta_value as avg,
p2.meta_value as total,
p1.meta_value * p2.meta_value as product
FROM $wpdb->postmeta as p1,
$wpdb->postmeta as p2
WHERE p1.meta_key = \'crfp-average-rating\'
AND p2.meta_key = \'crfp-total-ratings\'
AND p1.post_id = p2.post_id
"
);
foreach( $rows as $row ){
print_r( $row );
}