您好,我正在使用wpdb获取post\\u id,然后我想通过其值显示Posteta(sd\\u l2)订单
我使用这个代码
global $wpdb
$top5_ov_performance = $wpdb->get_results("SELECT post_id FROM ".$wpdb->prefix."postmeta WHERE meta_key = \'sd_type\' AND meta_value = \'desktop\'");
foreach ($top5_ov_performance as $ov_perforamnce) {
$new_number = ($ov_perforamnce->meta_value / $mother_number) * 100;
echo \'<div class="box">\';
echo \'<div style="width: \'.$new_number.\'%" class="fill">\';
echo \'<div class="fill-badge">\'.get_the_title($ov_perforamnce->post_id).\'</div>\';
echo \'</div>\';
echo \'<div class="empty">\';
echo \'<div class="empty-badge">\'.get_post_meta($ov_perforamnce->post_id,\'sd_l2\',true).\'</div>\';
echo \'</div>\';
echo \'</div>\';
}
最合适的回答,由SO网友:Alex Older 整理而成
您只需在SQL中传递要排序的字段:
ORDER BY post_id DESC
此示例将以最高的第一个ID(例如99、98、97)获取post\\U ID
或
ORDER BY post_id ASC
可以做到:1、2、3等等。
如果要按meta\\u值对结果进行分组,也可以选择:
GROUP BY meta_value