Add age rating filter to search
This commit is contained in:
parent
c63a0391d8
commit
7a8e7d5477
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -228,6 +228,12 @@ function fictioneer_extend_search_query( $query ) {
|
||||
);
|
||||
$story_status = reset( $story_status ) ?: 0;
|
||||
|
||||
$age_rating = array_intersect(
|
||||
[ $_GET['age_rating'] ?? 0 ],
|
||||
['Everyone', 'Teen', 'Mature', 'Adult']
|
||||
);
|
||||
$age_rating = reset( $age_rating ) ?: 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'] );
|
||||
@ -405,6 +411,22 @@ function fictioneer_extend_search_query( $query ) {
|
||||
);
|
||||
}
|
||||
|
||||
if ( $age_rating ) {
|
||||
$meta_query_stack[] = array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => 'fictioneer_story_rating',
|
||||
'value' => $age_rating,
|
||||
'compare' => '='
|
||||
),
|
||||
array(
|
||||
'key' => 'fictioneer_chapter_rating',
|
||||
'value' => $age_rating,
|
||||
'compare' => '='
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( $meta_query_stack ) {
|
||||
$meta_query = [];
|
||||
|
||||
|
@ -632,12 +632,42 @@ add_action( 'fictioneer_archive_loop_before', 'fictioneer_sort_order_filter_inte
|
||||
// SEARCH FORM & RESULTS
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Adds age rating select to advanced search form
|
||||
*
|
||||
* @since 5.12.5
|
||||
*
|
||||
* @param array $args Arguments passed to the search form.
|
||||
*/
|
||||
|
||||
function fictioneer_add_search_for_age_rating( $args ) {
|
||||
$age_rating = array_intersect(
|
||||
[ $_GET['age_rating'] ?? 0 ],
|
||||
['Everyone', 'Teen', 'Mature', 'Adult']
|
||||
);
|
||||
$age_rating = reset( $age_rating ) ?: 0;
|
||||
|
||||
// Start HTML ---> ?>
|
||||
<div class="search-form__select-wrapper select-wrapper">
|
||||
<div class="search-form__select-title"><?php _ex( 'Age Rating', 'Advanced search heading.', 'fictioneer' ); ?></div>
|
||||
<select name="age_rating" class="search-form__select" autocomplete="off" data-default="Any">
|
||||
<option value="Any" <?php echo ! $age_rating ? 'selected' : ''; ?>><?php _ex( 'Any', 'Advanced search option.', 'fictioneer' ); ?></option>
|
||||
<option value="Everyone" <?php echo $age_rating === 'Everyone' ? 'selected' : ''; ?>><?php echo fcntr( 'Everyone' ); ?></option>
|
||||
<option value="Teen" <?php echo $age_rating === 'Teen' ? 'selected' : ''; ?>><?php echo fcntr( 'Teen' ); ?></option>
|
||||
<option value="Mature" <?php echo $age_rating === 'Mature' ? 'selected' : ''; ?>><?php echo fcntr( 'Mature' ); ?></option>
|
||||
<option value="Adult" <?php echo $age_rating === 'Adult' ? 'selected' : ''; ?>><?php echo fcntr( 'Adult' ); ?></option>
|
||||
</select>
|
||||
</div>
|
||||
<?php // <--- End HTML
|
||||
}
|
||||
add_action( 'fictioneer_search_form_filters', 'fictioneer_add_search_for_age_rating' );
|
||||
|
||||
/**
|
||||
* Adds story status select to advanced search form
|
||||
*
|
||||
* @since 5.11.0
|
||||
*
|
||||
* @param array $args Arguments passed to the search form.
|
||||
* @param array $args Arguments passed to the search form.
|
||||
*/
|
||||
|
||||
function fictioneer_add_search_for_status( $args ) {
|
||||
|
@ -34,6 +34,12 @@ if ( $show_advanced ) {
|
||||
);
|
||||
$story_status = reset( $story_status ) ?: 0;
|
||||
|
||||
$age_rating = array_intersect(
|
||||
[ $_GET['age_rating'] ?? 0 ],
|
||||
['Everyone', 'Teen', 'Mature', 'Adult']
|
||||
);
|
||||
$age_rating = reset( $age_rating ) ?: 0;
|
||||
|
||||
$all_authors = get_users(
|
||||
array(
|
||||
'has_published_posts' => ['fcn_story', 'fcn_chapter', 'fcn_recommendation', 'post']
|
||||
@ -64,7 +70,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 || $story_status;
|
||||
$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 || $age_rating;
|
||||
|
||||
// Prime author cache
|
||||
if ( function_exists( 'update_post_author_caches' ) ) {
|
||||
@ -194,6 +200,13 @@ if ( $show_advanced ) {
|
||||
);
|
||||
?></span>
|
||||
|
||||
<span class="search-form__current-status"><?php
|
||||
printf(
|
||||
_x( '<b>Age Rating:</b> <span>%s</span>', 'Advanced search summary.', 'fictioneer' ),
|
||||
$age_rating ? fcntr( $age_rating ) : _x( 'Any', 'Advanced search option.', 'fictioneer' )
|
||||
);
|
||||
?></span>
|
||||
|
||||
<span class="search-form__current-status"><?php
|
||||
printf(
|
||||
_x( '<b>Status:</b> <span>%s</span>', 'Advanced search summary.', 'fictioneer' ),
|
||||
|
@ -97,16 +97,7 @@
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 1px;
|
||||
flex: 1 0 100%;
|
||||
|
||||
@include bp(480px) {
|
||||
flex: 1 1 40%;
|
||||
}
|
||||
|
||||
@include bp(640px) {
|
||||
flex: 0 1 auto;
|
||||
width: fit-content;
|
||||
}
|
||||
flex: 1 1 200px;
|
||||
}
|
||||
|
||||
&-title {
|
||||
|
Loading…
x
Reference in New Issue
Block a user