From a19088c2cbc3fe76692c36c44467316e6fc49594 Mon Sep 17 00:00:00 2001 From: ryan Date: Sat, 9 Apr 2005 17:30:57 +0000 Subject: [PATCH] Implement order and orderby for get_posts(). http://mosquito.wordpress.org/view.php?id=1161 Props: RummandDan git-svn-id: http://svn.automattic.com/wordpress/trunk@2525 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 51c2fa2043..016e266235 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1052,9 +1052,8 @@ function get_posts($args) { if (!isset($r['numberposts'])) $r['numberposts'] = 5; if (!isset($r['offset'])) $r['offset'] = 0; if (!isset($r['category'])) $r['category'] = ''; - // The following not implemented yet - if (!isset($r['orderby'])) $r['orderby'] = ''; - if (!isset($r['order'])) $r['order'] = ''; + if (!isset($r['orderby'])) $r['orderby'] = 'post_date'; + if (!isset($r['order'])) $r['order'] = 'DESC'; $now = current_time('mysql'); @@ -1063,8 +1062,8 @@ function get_posts($args) { ( empty( $r['category'] ) ? "" : ", $wpdb->post2cat " ) . " WHERE post_date <= '$now' AND (post_status = 'publish') ". ( empty( $r['category'] ) ? "" : "AND $wpdb->posts.ID = $wpdb->post2cat.post_id AND $wpdb->post2cat.category_id = " . $r['category']. " " ) . - " GROUP BY $wpdb->posts.ID ORDER BY post_date DESC LIMIT " . $r['offset'] . ',' . $r['numberposts'] ); - + " GROUP BY $wpdb->posts.ID ORDER BY " . $r['orderby'] . " " . $r['order'] . " LIMIT " . $r['offset'] . ',' . $r['numberposts'] ); + update_post_caches($posts); return $posts;