Created
July 14, 2017 13:13
-
-
Save ashleyfae/75d00738595c2d6783e05c6e8a5da8ab to your computer and use it in GitHub Desktop.
Novelist: Order series archive by publication date
This file contains hidden or 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 | |
/** | |
* 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