Opened 15 years ago
Closed 14 years ago
#14389 closed enhancement (fixed)
Refactor wp_get_recent_posts to use get_posts function
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 3.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Performance | Keywords: | has-patch needs testing |
Focuses: | Cc: |
Description
The wp_get_recent_posts function currently only allows 1 argument for number of posts, queries the database directly with $wpdb->get_results( $sql ) and returns the result set as an assc array.
This refactor would retain the above functionality by default as well as make the result set much more flexible, allowing access to all the args available within the get_posts() function.
Attachments (2)
Change History (8)
#1
@
15 years ago
- Component changed from General to Performance
- Milestone changed from Awaiting Review to 3.1
Instead of deprecating the argument, I think we can just do an is_numeric check on $args, and then turn it into $args = array( 'numberposts' => absint( $args ) )
.
Also, I think there's probably a cleaner way to handle the array conversion?
#2
@
15 years ago
Good idea. Yeah, I wasn't happy with the foreach loop. I'll look into other options.
#3
@
15 years ago
- Keywords dev-feedback added; needs-testing removed
This is the best solution I found for converting an Object to an array outside of the foreach loop I used but it would include introducing another function. Thoughts? (I couldn't find a wp function that already did this).
function wp_object_to_array( $object ) { if ( !is_object( $object ) && !is_array( $object ) ) return $object; if ( is_object( $object ) ) $object = get_object_vars( $object ); return array_map( 'wp_object_to_array', $object ); }
wp_get_recent_posts refactored