Fixes to the new search logic. Global search now is default.

This commit is contained in:
mateuswetah 2020-08-14 09:30:16 -03:00
parent b224b3b0b4
commit 4cdb20fc5c
5 changed files with 31 additions and 30 deletions

View File

@ -1,5 +1,5 @@
function onTainacanSearchSubmit($event) {
if (document['tainacan-search-form']) {
if (document['tainacan-search-form'].archive && tainacan_plugin !== undefined) {
@ -10,18 +10,19 @@ function onTainacanSearchSubmit($event) {
case 'tainacan-collections':
document['tainacan-search-form'].action = tainacan_plugin.theme_collection_list_url + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
break;
case 'everywhere':
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?everywhere=true&s=' + document['tainacan-search-form'].s.value : '');
break;
case 'posts':
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?onlyposts=true&s=' + document['tainacan-search-form'].s.value : '');
break;
case 'global':
default:
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
}
} else {
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
}
$event.preventDefault();
if ($event)
$event.preventDefault();
}
return true;
}

View File

@ -191,7 +191,8 @@ add_action( 'admin_head', 'tainacan_customize_editor_css');
* @param object $query The main WordPress query.
*/
function tainacan_include_items_in_search_results( $query ) {
if ( $_GET['everywhere'] && $query->is_main_query() && $query->is_search() && ! is_admin()) {
if ( $query->get( 'post_type' ) !== 'tainacan-collection' && !$_GET['onlyposts'] && $query->is_main_query() && $query->is_search() && ! is_admin()) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
$existing_post_types = $query->get( 'post_type' );

View File

@ -156,19 +156,18 @@ function tainacan_customize_register( $wp_customize ) {
'label' => __( 'Display option to search on tainacan collections list', 'tainacan-interface' )
) );
// Option to search globally posts, iem and collections
$wp_customize->add_setting( 'tainacan_search_global', array(
// Option to search on wordpress posts only
$wp_customize->add_setting( 'tainacan_search_on_posts', array(
'type' => 'theme_mod',
'default' => false,
'capability' => 'edit_theme_options',
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
) );
$wp_customize->add_control( 'tainacan_search_global', array(
$wp_customize->add_control( 'tainacan_search_on_posts', array(
'type' => 'checkbox',
'settings' => 'tainacan_search_global',
'settings' => 'tainacan_search_on_posts',
'section' => 'tainacan_header_search',
'label' => __( 'Display option to search globally on items, collections and posts', 'tainacan-interface' ),
'description'=> __( 'By searching via this mode, the list result will include posts, items and collecitions. You wil be able do distinguish them by a tag next to the title.', 'tainacan-interface' )
'label' => __( 'Display option to search only on WordPress posts', 'tainacan-interface' )
) );
/**

View File

@ -7,17 +7,17 @@
</button>
</span>
</div>
<?php if ( defined ( 'TAINACAN_VERSION' ) && (get_theme_mod('tainacan_search_on_items', false) || get_theme_mod('tainacan_search_on_collections', false) || get_theme_mod('tainacan_search_global', false) ) ) : ?>
<?php if ( defined ( 'TAINACAN_VERSION' ) && (get_theme_mod('tainacan_search_on_items', false) || get_theme_mod('tainacan_search_on_collections', false) || get_theme_mod('tainacan_search_on_posts', false) ) ) : ?>
<div class="search-controls">
<label for="search-on-posts">
<label for="search-global">
<input
type="radio"
value="posts"
value="global"
name="archive"
checked="checked"
id="search-on-posts">
<?php _e( 'Site posts', 'tainacan-interface' ); ?>
id="search-global">
<?php _e( 'Global search', 'tainacan-interface' ); ?>
</label>
<?php if ( get_theme_mod('tainacan_search_on_items', false) ) : ?>
@ -42,16 +42,16 @@
</label>
<?php endif;
if ( get_theme_mod('tainacan_search_global', false) ) : ?>
<label for="search-everywhere">
<input
type="radio"
value="everywhere"
name="archive"
id="search-everywhere">
<?php _e( 'Everywhere', 'tainacan-interface' ); ?>
</label>
if ( get_theme_mod('tainacan_search_on_posts', false) ) : ?>
<label for="search-on-posts">
<input
type="radio"
value="posts"
name="archive"
id="search-on-posts">
<?php _e( 'Site posts', 'tainacan-interface' ); ?>
</label>
<?php endif; ?>
</div>
<?php endif; ?>

View File

@ -1,5 +1,5 @@
<?php
if ( $_GET['everywhere'] ) {
if ( !$_GET['onlyposts'] && is_search() ) {
$post_type = get_post_type();
$post_type_object = get_post_type_object($post_type);
$post_type_label = $post_type_object->labels->singular_name;
@ -15,7 +15,7 @@
</div>
<?php endif; ?>
<div class="col-xs-12 blog-content <?php if ( has_post_thumbnail() ) :?>col-md-8 blog-flex<?php else : ?>col-md-12<?php endif; ?> align-self-center">
<?php if ( $_GET['everywhere'] ) : ?>
<?php if ( !$_GET['onlyposts'] && is_search() ) : ?>
<div class="title-area">
<h3 class="mb-3">
<a href="<?php the_permalink(); ?>" class="font-weight-bold"><?php the_title(); ?></a>