Last active
August 29, 2015 14:16
-
-
Save mrwweb/5a3511a08636f1a5cbca to your computer and use it in GitHub Desktop.
`DOING_AJAX` check added. Still doesn't work.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* For query modification */ | |
add_action( 'pre_get_posts', 'hai_resources_pre_get_posts' ); | |
function hai_resources_pre_get_posts( $query ) { | |
// stop immediately if we're in the admin or not working with the main query | |
if( ( is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) || !$query->is_main_query() ) { | |
return; | |
} | |
// modify resource library pages to orderby publication date | |
if( is_post_type_archive( 'hai_resources' ) || is_tax( 'hai_countries', 'hai_topics' ) ) { | |
$query->set( 'orderby', 'meta_val_num' ); | |
$query->set( 'order', 'ASC' ); | |
$query->set( 'meta_key', 'hai_publication_date' ); | |
$query->set( 'meta_type', 'datetime' ); | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment