从查询的数据库中,我们得到了这个
foreach ($child_posts as $child_post) {
$child_id = $child_post->ID;
$dayOfWeek = get_post_meta($child_id,'wpcf-day-of-week', true);
$time = get_post_meta($child_id,'wpcf-time', true);
$class[] = array('day' => $dayOfWeek, 'time' => $time, 'value' => $child_id);
}
{"classes":[
{"day":"7","time":"1500","value":13574},
{"day":"7","time":"1800","value":13573},
{"day":"4","time":"1900","value":11346},
{"day":"6","time":"1100","value":11494},
{"day":"5","time":"1800","value":11362},
{"day":"7","time":"1700","value":13572},
{"day":"6","time":"1600","value":11498},
{"day":"6","time":"1500","value":11496}]}
日 = 周一 - 周日
时间=军用时间
价值 = 我需要但不需要排序的东西
我需要先按天排序,然后按时间排序。并以原来的格式取回数据库
{"classes":[
{"day":"4","time":"1900","value":11346},
{"day":"5","time":"1800","value":11362},
{"day":"6","time":"1100","value":11494},
{"day":"6","time":"1500","value":11496},
{"day":"6","time":"1600","value":11498},
{"day":"7","time":"1500","value":13574},
{"day":"7","time":"1700","value":13572},
{"day":"7","time":"1800","value":13573}]}
我尝试使用 php 手册中的方法,但我仍然无法真正得到它。
这就是我所做的
foreach ($class as $key => $row) {
$day[$key] = $row['day'];
$time[$key] = $row['time'];
$value[$key] = $row['value'];
}
$class[] = array_multisort($day, SORT_DESC, $time, SORT_ASC, $class);
我知道我应该期待什么,但我不知道如何去获得它。希望有人可以在这里提供帮助:)
我的原始脚本:
$childargs = array(
'post_type' => 'class',
'numberposts' => -1,
'meta_query' => array(array('key' => '_wpcf_belongs_instructor_id', 'value' => $instructor_post_id))
);
$child_posts = get_posts($childargs);
//$child_posts = types_child_posts(‘class’);
foreach ($child_posts as $child_post) {
$child_id = $child_post->ID;
$dayOfWeek = get_post_meta($child_id,'wpcf-day-of-week', true);
$time = get_post_meta($child_id,'wpcf-time', true);
$class[] = array('day' => $dayOfWeek, 'time' => $time, 'value' => $child_id);
}
echo json_encode(
array("classes" => $class)
)
?>