Fix advanced search for taxonomies with same name
Seriously.
This commit is contained in:
parent
449073b9ce
commit
443e9dbb30
@ -11,6 +11,7 @@ if ( ! function_exists( 'fcn_keyword_search_taxonomies_input' ) ) {
|
||||
* @since 5.0.0
|
||||
*
|
||||
* @param array $taxonomies Array of WP_Term objects.
|
||||
* @param string $type The taxonomy type.
|
||||
* @param string $query_var Name of the submitted collection field.
|
||||
* @param string $and_var Name of the submitted operator field.
|
||||
* @param string $singular Singular display name of taxonomy.
|
||||
@ -18,7 +19,7 @@ if ( ! function_exists( 'fcn_keyword_search_taxonomies_input' ) ) {
|
||||
* @param array $args Optional arguments.
|
||||
*/
|
||||
|
||||
function fcn_keyword_search_taxonomies_input( $taxonomies, $query_var, $and_var, $singular, $plural, $args = [] ) {
|
||||
function fcn_keyword_search_taxonomies_input( $taxonomies, $type, $query_var, $and_var, $singular, $plural, $args = [] ) {
|
||||
// Setup
|
||||
$and = sanitize_key( $_GET[ $and_var ] ?? 0, true );
|
||||
$query_list = sanitize_text_field( wp_strip_all_tags( $_GET[ $query_var ] ?? '', true ) );
|
||||
@ -69,7 +70,7 @@ if ( ! function_exists( 'fcn_keyword_search_taxonomies_input' ) ) {
|
||||
?>
|
||||
<div class="keyword-input__input-wrapper">
|
||||
<div class="keyword-input__tab-suggestion"></div>
|
||||
<input type="text" class="keyword-input__input" style="width: 16px;" autocomplete="off">
|
||||
<input type="text" class="keyword-input__input" data-type="<?php echo $type; ?>" style="width: 16px;" autocomplete="off">
|
||||
</div>
|
||||
</label>
|
||||
<div class="keyword-input__hints"><?php
|
||||
@ -147,7 +148,7 @@ if ( ! function_exists( 'fcn_keyword_search_authors_input' ) ) {
|
||||
?>
|
||||
<div class="keyword-input__input-wrapper">
|
||||
<div class="keyword-input__tab-suggestion"></div>
|
||||
<input type="text" class="keyword-input__input" style="width: 16px;" autocomplete="off">
|
||||
<input type="text" class="keyword-input__input" data-type="author" style="width: 16px;" autocomplete="off">
|
||||
</div>
|
||||
</label>
|
||||
<div class="keyword-input__hints"><?php
|
||||
|
2
js/application.min.js
vendored
2
js/application.min.js
vendored
File diff suppressed because one or more lines are too long
4
js/complete.min.js
vendored
4
js/complete.min.js
vendored
File diff suppressed because one or more lines are too long
@ -82,14 +82,14 @@ if ( $show_advanced ) {
|
||||
$allow_list = [];
|
||||
|
||||
foreach ( $all_terms as $term ) {
|
||||
$allow_list[ base64_encode( mb_strtolower( $term->name, 'UTF-8' ) ) ] = $term->term_id;
|
||||
$allow_list[ $term->taxonomy . '_' . base64_encode( mb_strtolower( $term->name, 'UTF-8' ) ) ] = $term->term_id;
|
||||
}
|
||||
|
||||
if ( ! $skip_author_keywords ) {
|
||||
foreach ( $all_authors as $author ) {
|
||||
$author_key = base64_encode( mb_strtolower( $author->display_name, 'UTF-8' ) );
|
||||
|
||||
$allow_list[ $author_key . '_' . $author->ID ] = $author->ID;
|
||||
$allow_list[ 'author_' . $author_key . '_' . $author->ID ] = $author->ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -365,27 +365,27 @@ if ( $show_advanced ) {
|
||||
|
||||
<?php if ( ! empty( $all_genres ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Genres', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_genres, 'genres', 'genres_and', 'genre', 'genres', array( 'preselected' => $args['preselect_genres'] ?? null ) ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_genres, 'fcn_genre', 'genres', 'genres_and', 'genre', 'genres', array( 'preselected' => $args['preselect_genres'] ?? null ) ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_fandoms ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Fandoms', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_fandoms, 'fandoms', 'fandoms_and', 'fandom', 'fandoms', array( 'preselected' => $args['preselect_fandoms'] ?? null ) ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_fandoms, 'fcn_fandom', 'fandoms', 'fandoms_and', 'fandom', 'fandoms', array( 'preselected' => $args['preselect_fandoms'] ?? null ) ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_characters ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Characters', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_characters, 'characters', 'characters_and', 'character', 'characters', array( 'preselected' => $args['preselect_characters'] ?? null ) ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_characters, 'fcn_character', 'characters', 'characters_and', 'character', 'characters', array( 'preselected' => $args['preselect_characters'] ?? null ) ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_tags ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Tags', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_tags, 'tags', 'tags_and', 'tag', 'tags', array( 'preselected' => $args['preselect_tags'] ?? null ) ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_tags, 'post_tag', 'tags', 'tags_and', 'tag', 'tags', array( 'preselected' => $args['preselect_tags'] ?? null ) ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_warnings ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Warnings', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_warnings, 'warnings', 'warnings_and', 'warning', 'warnings', array( 'preselected' => $args['preselect_warnings'] ?? null ) ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_warnings, 'fcn_content_warning', 'warnings', 'warnings_and', 'warning', 'warnings', array( 'preselected' => $args['preselect_warnings'] ?? null ) ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( count( $all_authors ) > 1 ) : ?>
|
||||
@ -402,27 +402,27 @@ if ( $show_advanced ) {
|
||||
|
||||
<?php if ( ! empty( $all_genres ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Exclude Genres', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_genres, 'ex_genres', 'ex_genres_and', 'genre', 'genres' ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_genres, 'fcn_genre', 'ex_genres', 'ex_genres_and', 'genre', 'genres' ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_fandoms ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Exclude Fandoms', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_fandoms, 'ex_fandoms', 'ex_fandoms_and', 'fandom', 'fandoms' ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_fandoms, 'fcn_fandom', 'ex_fandoms', 'ex_fandoms_and', 'fandom', 'fandoms' ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_characters ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Exclude Characters', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_characters, 'ex_characters', 'ex_characters_and', 'character', 'characters' ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_characters, 'fcn_character', 'ex_characters', 'ex_characters_and', 'character', 'characters' ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_tags ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Exclude Tags', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_tags, 'ex_tags', 'ex_tags_and', 'tag', 'tags' ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_tags, 'post_tag', 'ex_tags', 'ex_tags_and', 'tag', 'tags' ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( ! empty( $all_warnings ) ) : ?>
|
||||
<h6 class="search-form__option-headline"><?php _ex( 'Exclude Warnings', 'Advanced search heading.', 'fictioneer' ); ?></h6>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_warnings, 'ex_warnings', 'ex_warnings_and', 'warning', 'warnings' ); ?>
|
||||
<?php fcn_keyword_search_taxonomies_input( $all_warnings, 'fcn_content_warning', 'ex_warnings', 'ex_warnings_and', 'warning', 'warnings' ); ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ( count( $all_authors ) > 1 && ! $skip_author_keywords ) : ?>
|
||||
|
@ -1725,6 +1725,7 @@ fcn_theBody.addEventListener(
|
||||
class FCN_KeywordInput {
|
||||
constructor(input) {
|
||||
this.input = input;
|
||||
this.type = input.dataset.type;
|
||||
this.operator = input.closest('.keyword-input').querySelector('.keyword-input__operator input');
|
||||
this.inputWrapper = input.closest('.keyword-input__input-wrapper');
|
||||
this.block = input.closest('.keyword-input');
|
||||
@ -1828,11 +1829,11 @@ class FCN_KeywordInput {
|
||||
addNode(text = null, trigger = null) {
|
||||
// Get and prepare value
|
||||
const name = text ?? this.input.value.replace(',', '');
|
||||
let value = this.allowList[this.encode(name)];
|
||||
let value = this.allowList[`${this.type}_${this.encode(name)}`];
|
||||
|
||||
// Author names can be duplicates
|
||||
if ((this.collection.name == 'authors' || this.collection.name == 'ex_authors') && trigger) {
|
||||
value = this.allowList[this.encode(name) + `_${trigger.value}`];
|
||||
value = this.allowList[`${this.type}_${this.encode(name)}_${trigger.value}`];
|
||||
}
|
||||
|
||||
// Only allowed value and no duplicates
|
||||
|
Loading…
x
Reference in New Issue
Block a user