Skip to content

Instantly share code, notes, and snippets.

@mrwweb
Last active August 29, 2015 14:16
Show Gist options
  • Save mrwweb/5a3511a08636f1a5cbca to your computer and use it in GitHub Desktop.
Save mrwweb/5a3511a08636f1a5cbca to your computer and use it in GitHub Desktop.
`DOING_AJAX` check added. Still doesn't work.
<?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