WordPress.org

Make WordPress Core

Ticket #14389: 14389-2.diff

File 14389-2.diff, 1.9 KB (added by blepoxp, 8 years ago)

Adjusts arguments and replaces foreach cast with get_object_vars

  • 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) {
    2049         global $wpdb;
     2051function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
    20502052
    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();
    20552076        }
    20562077
    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;
    20592079
    2060         return $result ? $result : array();
    20612080}
    20622081
    20632082/**