Ticket #14389: 14389-2.diff
File 14389-2.diff, 1.9 KB (added by , 15 years ago) |
---|
-
wp-includes/post.php
2040 2040 * Retrieve number of recent posts. 2041 2041 * 2042 2042 * @since 1.0.0 2043 * @uses $wpdb 2043 * @uses wp_parse_args() 2044 * @uses get_posts() 2044 2045 * 2045 * @param int $num Optional, default is 10. Number of posts to get. 2046 * @return array List of posts. 2046 * @param string $deprecated Deprecated. 2047 * @param array $args Optional. Overrides defaults. 2048 * @param string $output Optional. 2049 * @return unknown. 2047 2050 */ 2048 function wp_get_recent_posts($num = 10) { 2049 global $wpdb; 2051 function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { 2050 2052 2051 // Set the limit clause, if we got a limit 2052 $num = (int) $num; 2053 if ( $num ) { 2054 $limit = "LIMIT $num"; 2053 if ( is_numeric( $args ) ) 2054 $args = array( 'numberposts' => absint( $args ) ); 2055 2056 // Set default arguments 2057 $defaults = array( 2058 'numberposts' => 10, 'offset' => 0, 2059 'category' => 0, 'orderby' => 'post_date', 2060 'order' => 'DESC', 'include' => '', 2061 'exclude' => '', 'meta_key' => '', 2062 'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private', 2063 'suppress_filters' => true 2064 ); 2065 2066 $r = wp_parse_args( $args, $defaults ); 2067 2068 $results = get_posts( $r ); 2069 2070 // Backward compatibility. Prior to 3.1 expected posts to be returned in array 2071 if ( ARRAY_A == $output ){ 2072 foreach( $results as $key => $result ) { 2073 $results[$key] = get_object_vars( $result ); 2074 } 2075 return $results ? $results : array(); 2055 2076 } 2056 2077 2057 $sql = "SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status IN ( 'draft', 'publish', 'future', 'pending', 'private' ) ORDER BY post_date DESC $limit"; 2058 $result = $wpdb->get_results($sql, ARRAY_A); 2078 return $results ? $results : false; 2059 2079 2060 return $result ? $result : array();2061 2080 } 2062 2081 2063 2082 /**