クエリされたデータベースから、これを取得しました
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)
)
?>