Skip to content

Instantly share code, notes, and snippets.

@ashleyfae
Created July 14, 2017 13:13
Show Gist options
  • Save ashleyfae/75d00738595c2d6783e05c6e8a5da8ab to your computer and use it in GitHub Desktop.
Save ashleyfae/75d00738595c2d6783e05c6e8a5da8ab to your computer and use it in GitHub Desktop.
Novelist: Order series archive by publication date
<?php
/**
* Modify Book Query
*
* Modifies the WP_Query to change the series archive "orderby" parameter to use
* the book's publication date rather than the number in the series. This
* eliminates the need to fill out the book series number.
*
* @param WP_Query $query
*
* @return void
*/
function ag_novelist_series_archive_orderby( $query ) {
if ( ! $query->is_main_query() || is_admin() ) {
return;
}
if ( is_tax( 'novelist-series' ) ) {
$query->set( 'orderby', 'meta_value_num' );
$query->set( 'order', 'ASC' );
$query->set( 'meta_key', 'novelist_pub_date_timestamp' );
}
}
add_action( 'pre_get_posts', 'ag_novelist_series_archive_orderby', 100 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment