所以我想添加ORDER BY
我的查询,但它不起作用,因为日期字段在表单中2013-02-27 00:00:00
。如何即时转换它以便我可以使用它ORDER BY
?这是我的查询:
$sql = "SELECT * FROM $wpdb->posts";
$sql .= " INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id";
$sql .= " WHERE $wpdb->posts.post_type = 'task'";
$sql .= " AND $wpdb->postmeta.post_id IN ( SELECT `post_id` FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = '_completed' AND $wpdb->postmeta.meta_value = '0' )";
$sql .= " AND $wpdb->postmeta.post_id IN ( SELECT `post_id` FROM $wpdb->postmeta WHERE $wpdb->postmeta.meta_key = '_assigned' AND $wpdb->postmeta.meta_value = '%s' )";
$sql .= " GROUP BY $wpdb->postmeta.post_id";
$sql .= " ORDER BY $wpdb->postmeta._due ASC";
$tasks = $wpdb->get_results( sprintf( $sql, $user_id ) );
有问题的字段在_due
表中wp_postmeta
。这是针对 Wordpress 的,但由于这是一个 MYSQL 问题,我想我会在这里问它。谢谢!