Sorting not working on Custom Post Type
Hey guys,
I have a custom post type called “booking”, with custom post statuses:
- Upcoming
- Past
- Cancelled
- Late Cancelled
- Charged Cancelled
- No Show
The problem
When viewing the Bookings screen, the post status is set to “All” on default. In classes/sortable/classes/model.php:308
the get_posts method assumes default status to be array('any', 'trash')
. Any doesn’t translate to my list of custom post statuses.
Here is what I did to fix it:
public function get_posts( $args = array() ) {
$default_post_status = $this->storage_model->get_post_type() == 'booking'
? array( 'upcoming', 'past', 'cancelled', 'late-cancelled', 'charged-cancelled', 'no-show' )
: array( 'any', 'trash' );
$defaults = array(
'posts_per_page' => - 1,
'post_status' => $default_post_status,
'post_type' => $this->storage_model->get_post_type(),
'fields' => 'ids',
'no_found_rows' => 1, // lowers our carbon footprint
);
$post_ids = (array) get_posts( array_merge( $defaults, $args ) );
return $post_ids;
}
It would be nice if you had a filter called “default_sorting_post_status”, and I can hook into it rather than changing core.
Thanks!
You must be logged in to reply to this topic.