Skip to content
Snippets Groups Projects
Commit 2e723b07 authored by Erick Hitter's avatar Erick Hitter
Browse files

Sort all timeline queries by start date, unless in the admin and using list table sorting controls.

Fixes #5. Closes #5.
parent f653ff6c
No related branches found
No related tags found
No related merge requests found
......@@ -61,6 +61,8 @@ class ETH_Timeline {
private function setup() {
add_action( 'init', array( $this, 'action_init' ) );
add_action( 'pre_get_posts', array( $this, 'action_pre_get_posts' ) );
add_action( 'admin_enqueue_scripts', array( $this, 'action_admin_enqueue_scripts' ) );
add_action( 'add_meta_boxes_' . $this->post_type, array( $this, 'action_add_meta_boxes' ) );
add_action( 'save_post', array( $this, 'action_save_post' ) );
......@@ -136,6 +138,25 @@ class ETH_Timeline {
// ) );
}
/**
* Force all timeline queries to be sorted by start date.
* Doesn't interfere with admin list table sorting.
*
* @param object $query
* @uses is_admin
* @action pre_get_posts
* @return null
*/
public function action_pre_get_posts( $query ) {
if ( $this->post_type == $query->get( 'post_type' ) ) {
if ( is_admin() && isset( $_GET['orderby'] ) )
return;
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'meta_key', $this->meta_start );
}
}
/**
* Enqueue admin assets
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment