From 5d442f5d540163d381a353c4d5ee36811c6410de Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Sat, 28 Oct 2023 16:17:56 +0200 Subject: [PATCH] Allow stories to be ordered by latest chapter update --- INSTALLATION.md | 3 ++- functions.php | 5 +++++ includes/functions/_query_helpers.php | 2 +- stories.php | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/INSTALLATION.md b/INSTALLATION.md index d7c94e3b..5b21aea0 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -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`. diff --git a/functions.php b/functions.php index f8030005..7517fb03 100644 --- a/functions.php +++ b/functions.php @@ -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 // diff --git a/includes/functions/_query_helpers.php b/includes/functions/_query_helpers.php index 72be28d7..4231f312 100644 --- a/includes/functions/_query_helpers.php +++ b/includes/functions/_query_helpers.php @@ -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 ( diff --git a/stories.php b/stories.php index 2b6b19a2..7ba68f54 100644 --- a/stories.php +++ b/stories.php @@ -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 );