我能想到的最简单的解决方案是将posts元表与posts表连接两次。修改codex 例如,您可以使用以下位:
$querystr = "
SELECT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta1, $wpdb->postmeta wpostmeta2
WHERE wposts.ID = wpostmeta1.post_id
AND wposts.ID = wpostmeta2.post_id
AND wpostmeta1.meta_key = \'genus\'
AND wpostmeta2.meta_key = \'species\'
AND wposts.post_type = \'post\'
ORDER BY wpostmeta1.meta_value ASC,
wpostmeta2.meta_value ASC
";