diff --git a/ACTIONS.md b/ACTIONS.md index bb16ed4d..54e199b7 100644 --- a/ACTIONS.md +++ b/ACTIONS.md @@ -847,6 +847,17 @@ Fires right after the search form has been rendered. --- +### `do_action( 'fictioneer_search_form_filters', $args )` +Fires after the search form fields for type, match, sort, and order have been rendered. This allows you to render additional fields. Note that any additional fields must also be manually added to the query, see `_search.php` partial. + +**Parameters:** +* $args (array) – Arguments passed to the search form. + +**Hooked actions:** +* `fictioneer_add_search_for_status()` – HTML for story status select. Priority 10. + +--- + ### `do_action( 'fictioneer_search_no_params' )` Fires right after opening the article’s no-params `
` container in the `search.php` template. diff --git a/includes/functions/_search.php b/includes/functions/_search.php index 67d1e5c1..2ebd2bb5 100644 --- a/includes/functions/_search.php +++ b/includes/functions/_search.php @@ -180,6 +180,7 @@ if ( ! function_exists( 'fcn_keyword_search_authors_input' ) ) { * Extend search query with custom input * * @since 5.0.0 + * @since 5.11.0 - Added meta query for story status. * * @param WP_Query $query The query. */ @@ -221,6 +222,12 @@ function fictioneer_extend_search_query( $query ) { $ex_warnings = empty( $_GET['ex_warnings'] ) ? [] : array_map( 'absint', explode( ',', $_GET['ex_warnings'] ) ); $ex_tags = empty( $_GET['ex_tags'] ) ? [] : array_map( 'absint', explode( ',', $_GET['ex_tags'] ) ); + $story_status = array_intersect( + [ $_GET['story_status'] ?? 0 ], + ['Completed', 'Ongoing', 'Oneshot', 'Hiatus', 'Canceled'] + ); + $story_status = reset( $story_status ) ?: 0; + // Exclude pages if necessary if ( $is_any_post || empty( $_GET['post_type'] ) ) { $query->set( 'post_type', ['post', 'fcn_story', 'fcn_chapter', 'fcn_collection', 'fcn_recommendation'] ); @@ -384,6 +391,19 @@ function fictioneer_extend_search_query( $query ) { if ( ! empty( $authors ) ) { $query->set( 'author', implode( ',', $authors ) ); } + + // Meta query + if ( $story_status ) { + $meta_query = array( + array( + 'key' => 'fictioneer_story_status', + 'value' => $story_status, + 'compare' => '=' + ) + ); + + $query->set( 'meta_query', $meta_query ); + } } if ( ! get_option( 'fictioneer_disable_theme_search' ) ) { diff --git a/includes/functions/hooks/_general_hooks.php b/includes/functions/hooks/_general_hooks.php index 4a223df7..a3c6dcf2 100644 --- a/includes/functions/hooks/_general_hooks.php +++ b/includes/functions/hooks/_general_hooks.php @@ -621,9 +621,40 @@ add_action( 'fictioneer_recommendations_after_content', 'fictioneer_sort_order_f add_action( 'fictioneer_archive_loop_before', 'fictioneer_sort_order_filter_interface', 10 ); // ============================================================================= -// SEARCH RESULTS +// SEARCH FORM & RESULTS // ============================================================================= +/** + * Adds story status select to advanced search form + * + * @since 5.11.0 + * + * @param array $args Arguments passed to the search form. + */ + +function fictioneer_add_search_for_status( $args ) { + $story_status = array_intersect( + [ $_GET['story_status'] ?? 0 ], + ['Completed', 'Ongoing', 'Oneshot', 'Hiatus', 'Canceled'] + ); + $story_status = reset( $story_status ) ?: 0; + + // Start HTML ---> ?> +
+
+ +
+ @@ -21,6 +22,12 @@ $sentence = sanitize_text_field( $_GET['sentence'] ?? 0 ); $order = sanitize_text_field( $_GET['order'] ?? 'desc' ); $orderby = sanitize_text_field( $_GET['orderby'] ?? 'modified' ); +$story_status = array_intersect( + [ $_GET['story_status'] ?? 0 ], + ['Completed', 'Ongoing', 'Oneshot', 'Hiatus', 'Canceled'] +); +$story_status = reset( $story_status ) ?: 0; + $queried_genres = sanitize_text_field( $_GET['genres'] ?? 0 ); $queried_fandoms = sanitize_text_field( $_GET['fandoms'] ?? 0 ); $queried_characters = sanitize_text_field( $_GET['characters'] ?? 0 ); @@ -39,6 +46,7 @@ $hook_args = array( 'sentence' => $sentence, 'order' => $order, 'orderby' => $orderby, + 'story_status' => $story_status, 'queried_genres' => $queried_genres, 'queried_fandoms' => $queried_fandoms, 'queried_characters' => $queried_characters, @@ -52,7 +60,7 @@ $hook_args = array( ); // Advanced search? -$is_advanced_search = $post_type != 'any' || $sentence != '0' || $order != 'desc' || $orderby != 'modified' || $queried_tags || $queried_genres || $queried_fandoms || $queried_characters || $queried_warnings || $queried_ex_tags || $queried_ex_genres || $queried_ex_fandoms || $queried_ex_characters || $queried_ex_warnings; +$is_advanced_search = $post_type != 'any' || $sentence != '0' || $order != 'desc' || $orderby != 'modified' || $queried_tags || $queried_genres || $queried_fandoms || $queried_characters || $queried_warnings || $queried_ex_tags || $queried_ex_genres || $queried_ex_fandoms || $queried_ex_characters || $queried_ex_warnings || $story_status; $hook_args['is_advanced_search'] = $is_advanced_search; diff --git a/searchform.php b/searchform.php index 4a1bb968..87957252 100644 --- a/searchform.php +++ b/searchform.php @@ -5,6 +5,7 @@ * @package WordPress * @subpackage Fictioneer * @since 5.0.0 + * @since 5.11.0 - Added 'fictioneer_search_form_filters' action hook. * * @internal $args['simple'] Optional. Hide advanced options. * @internal $args['placeholder'] Optional. Change search placeholder. @@ -27,6 +28,12 @@ if ( $show_advanced ) { $order = sanitize_text_field( $_GET['order'] ?? 'desc' ); $orderby = sanitize_text_field( $_GET['orderby'] ?? 'modified' ); + $story_status = array_intersect( + [ $_GET['story_status'] ?? 0 ], + ['Completed', 'Ongoing', 'Oneshot', 'Hiatus', 'Canceled'] + ); + $story_status = reset( $story_status ) ?: 0; + $all_authors = get_users( array( 'has_published_posts' => ['fcn_story', 'fcn_chapter', 'fcn_recommendation', 'post'] @@ -57,7 +64,7 @@ if ( $show_advanced ) { $queried_ex_warnings = sanitize_text_field( $_GET['ex_warnings'] ?? 0 ); $queried_ex_tags = sanitize_text_field( $_GET['ex_tags'] ?? 0 ); - $is_advanced_search = $post_type != 'any' || $sentence != '0' || $order != 'desc' || $orderby != 'modified' || $queried_tags || $queried_genres || $queried_fandoms || $queried_characters || $queried_warnings || $queried_ex_tags || $queried_ex_genres || $queried_ex_fandoms || $queried_ex_characters || $queried_ex_warnings || $queried_authors_in || $queried_authors_out || $author_name; + $is_advanced_search = $post_type != 'any' || $sentence != '0' || $order != 'desc' || $orderby != 'modified' || $queried_tags || $queried_genres || $queried_fandoms || $queried_characters || $queried_warnings || $queried_ex_tags || $queried_ex_genres || $queried_ex_fandoms || $queried_ex_characters || $queried_ex_warnings || $queried_authors_in || $queried_authors_out || $author_name || $story_status; // Prime author cache if ( function_exists( 'update_post_author_caches' ) ) { @@ -187,6 +194,13 @@ if ( $show_advanced ) { ); ?> + Status: %s', 'Advanced search summary.', 'fictioneer' ), + $story_status ? fcntr( $story_status ) : _x( 'Any', 'Advanced search option.', 'fictioneer' ) + ); + ?> + + 1 ) : ?>