Allow stories to be ordered by latest chapter update

This commit is contained in:
Tetrakern 2023-10-28 16:17:56 +02:00
parent 7301ee4484
commit 5d442f5d54
4 changed files with 14 additions and 2 deletions

View File

@ -833,7 +833,7 @@ function fictioneer_clause_sticky_stories( $clauses, $wp_query ) {
// Setup
$vars = $wp_query->query_vars;
$allowed_queries = ['stories_list', 'latest_stories', 'latest_stories_compact', 'author_stories'];
$allowed_orderby = ['date', 'modified', 'title'];
$allowed_orderby = ['date', 'modified', 'title', 'meta_value', 'meta_value date', 'meta_value modified', 'meta_value title'];
// Return if wrong query
if (
@ -923,3 +923,4 @@ define( 'CONSTANT_NAME', value );
| FICTIONEER_ENABLE_STORY_DATA_META_CACHE | boolean | Whether to "cache" story data in a meta field. Default `true`.
| FICTIONEER_ENABLE_FRONTEND_ACF | boolean | Whether to load ACF on the frontend. Default `false`.
| FICTIONEER_ENABLE_MENU_TRANSIENTS | boolean | Whether to cache nav menus as Transients. Default `true`.
| FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER | boolean | Whether to order updated stories based on the latest chapter added, excluding stories without chapters. Default `false`.

View File

@ -351,6 +351,11 @@ if ( ! defined( 'FICTIONEER_ENABLE_MENU_TRANSIENTS' ) ) {
define( 'FICTIONEER_ENABLE_MENU_TRANSIENTS', true );
}
// Boolean: Order stories by last updated chapter timestamp
if ( ! defined( 'FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER' ) ) {
define( 'FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER', false );
}
// =============================================================================
// FAST REQUESTS
//

View File

@ -229,7 +229,7 @@ function fictioneer_clause_sticky_stories( $clauses, $wp_query ) {
// Setup
$vars = $wp_query->query_vars;
$allowed_queries = ['stories_list', 'latest_stories', 'latest_stories_compact', 'author_stories'];
$allowed_orderby = ['date', 'modified', 'title'];
$allowed_orderby = ['date', 'modified', 'title', 'meta_value', 'meta_value date', 'meta_value modified', 'meta_value title'];
// Return if wrong query
if (

View File

@ -47,6 +47,12 @@ $query_args = array (
)
);
// Order by latest chapter update timestamp?
if ( FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER && $orderby === 'modified' ) {
$query_args['orderby'] = 'meta_value modified';
$query_args['meta_key'] = 'fictioneer_chapters_added';
}
// Append date query (if any)
$query_args = fictioneer_append_date_query( $query_args, $ago, $orderby );