diff --git a/chapters.php b/chapters.php index 5406dcdb..a38f05da 100644 --- a/chapters.php +++ b/chapters.php @@ -70,6 +70,12 @@ foreach ( $meta_query_stack as $part ) { $query_args['meta_query'][] = $part; } +// Order by words? +if ( $orderby === 'words' ) { + $query_args['orderby'] = 'meta_value_num modified'; + $query_args['meta_key'] = '_word_count'; +} + // Append date query (if any) $query_args = fictioneer_append_date_query( $query_args, $ago, $orderby ); diff --git a/includes/functions/_query_helpers.php b/includes/functions/_query_helpers.php index 163ee3a1..017e298a 100644 --- a/includes/functions/_query_helpers.php +++ b/includes/functions/_query_helpers.php @@ -14,7 +14,7 @@ */ function fictioneer_allowed_orderby() { - $defaults = ['modified', 'date', 'title', 'rand', 'name', 'ID', 'comment_count', 'type', 'post__in', 'author']; + $defaults = ['modified', 'date', 'title', 'rand', 'name', 'ID', 'comment_count', 'type', 'post__in', 'author', 'words']; return apply_filters( 'fictioneer_filter_allowed_orderby', $defaults ); } diff --git a/includes/functions/hooks/_general_hooks.php b/includes/functions/hooks/_general_hooks.php index 7d998e15..963ee4d3 100644 --- a/includes/functions/hooks/_general_hooks.php +++ b/includes/functions/hooks/_general_hooks.php @@ -488,19 +488,26 @@ function fictioneer_sort_order_filter_interface( $args ) { // Order menu options $orderby_menu = array( 'modified' => array( - 'label' => __( 'Updated', 'fictioneer' ), + 'label' => _x( 'Updated', 'Sort and filter option.', 'fictioneer' ), 'url' => add_query_arg( array( 'orderby' => 'modified' ), $current_url ) . '#sof' ), 'date' => array( - 'label' => __( 'Published', 'fictioneer' ), + 'label' => _x( 'Published', 'Sort and filter option.', 'fictioneer' ), 'url' => add_query_arg( array( 'orderby' => 'date' ), $current_url ) . '#sof' ), 'title' => array( - 'label' => __( 'By Title', 'fictioneer' ), + 'label' => _x( 'Title', 'Sort and filter option.', 'fictioneer' ), 'url' => add_query_arg( array( 'orderby' => 'title' ), $current_url ) . '#sof' ) ); + if ( ! is_archive() ) { + $orderby_menu['words'] = array( + 'label' => _x( 'Words', 'Sort and filter option.', 'fictioneer' ), + 'url' => add_query_arg( array( 'orderby' => 'words' ), $current_url ) . '#sof' + ); + } + // Filter orderby options $orderby_menu = apply_filters( 'fictioneer_filter_sof_orderby_options', $orderby_menu, $current_url, $args ); diff --git a/stories.php b/stories.php index f36d0a4b..a15f550a 100644 --- a/stories.php +++ b/stories.php @@ -71,6 +71,12 @@ foreach ( $meta_query_stack as $part ) { $query_args['meta_query'][] = $part; } +// Order by words? +if ( $orderby === 'words' ) { + $query_args['orderby'] = 'meta_value_num modified'; + $query_args['meta_key'] = 'fictioneer_story_total_word_count'; +} + // Order by latest chapter update timestamp? if ( FICTIONEER_ORDER_STORIES_BY_LATEST_CHAPTER && $orderby === 'modified' ) { $query_args['orderby'] = 'meta_value modified';