Make WordPress Core

Ticket #14389: 14389.diff

File 14389.diff, 2.0 KB (added by blepoxp, 15 years ago)

wp_get_recent_posts refactored

  • wp-includes/post.php

     
    20402040 * Retrieve number of recent posts.
    20412041 *
    20422042 * @since 1.0.0
    2043  * @uses $wpdb
     2043 * @uses wp_parse_args()
     2044 * @uses get_posts()
    20442045 *
    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.
    20472050 */
    2048 function wp_get_recent_posts($num = 10) {
     2051function wp_get_recent_posts( $deprecated = '', $args = null, $output = ARRAY_A ) {
    20492052        global $wpdb;
    20502053
    2051         // Set the limit clause, if we got a limit
    2052         $num = (int) $num;
    2053         if ( $num ) {
    2054                 $limit = "LIMIT $num";
     2054        if ( !empty( $deprecated ) ) {
     2055                if ( function_exists( 'deprecated_argument' ) )
     2056                        _deprecated_argument( __FUNCTION__, '3.1' );
     2057                $args['numberposts'] = $deprecated;
    20552058        }
    20562059
    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);
     2060        // Set default arguments
     2061        $defaults = array(
     2062                'numberposts' => 10, 'offset' => 0,
     2063                'category' => 0, 'orderby' => 'post_date',
     2064                'order' => 'DESC', 'include' => '',
     2065                'exclude' => '', 'meta_key' => '',
     2066                'meta_value' =>'', 'post_type' => 'post', 'post_status' => 'draft, publish, future, pending, private',
     2067                'suppress_filters' => true
     2068        );
     2069       
     2070        $r = wp_parse_args( $args, $defaults );
    20592071
    2060         return $result ? $result : array();
     2072        $results = get_posts( $r );
     2073       
     2074        // Backward compatibility. Prior to 3.1 expected posts to be returned in array
     2075        if ( ARRAY_A == $output ){
     2076                foreach( $results as $key => $result ) {
     2077                        $results[$key] = (array) $result;
     2078                }
     2079                return $results ? $results : array();
     2080        }
     2081
     2082        return $results ? $results : false;
     2083
    20612084}
    20622085
    20632086/**