From 420a4449e88a3f6cb38baa4f5a972f5c097acb70 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Thu, 5 Nov 2020 15:29:13 -0300 Subject: [PATCH] Fixes wrong redirection of search params. (https://github.com/tainacan/tainacan/issues/428) --- src/functions.php | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/functions.php b/src/functions.php index 7d0f724..857e0bc 100644 --- a/src/functions.php +++ b/src/functions.php @@ -192,18 +192,27 @@ add_action( 'admin_head', 'tainacan_customize_editor_css'); */ function tainacan_include_items_in_search_results( $query ) { - if ( defined ('TAINACAN_VERSION') && $query->get( 'post_type' ) !== 'tainacan-collection' && (!isset($_GET['onlyposts']) || !$_GET['onlyposts']) && (!isset($_GET['onlypages']) || !$_GET['onlypages']) && $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' ); + if ( !is_post_type_archive() && isset($_GET['s']) ) { + if ( defined ('TAINACAN_VERSION') && + $query->get( 'post_type' ) !== 'tainacan-collection' && + (!isset($_GET['onlyposts']) || !$_GET['onlyposts']) && + (!isset($_GET['onlypages']) || !$_GET['onlypages']) && + $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' ); - if ( !is_array($existing_post_types) ) - $existing_post_types = [ $existing_post_types ]; + if ( !is_array($existing_post_types) ) + $existing_post_types = [ $existing_post_types ]; - $query->set( 'post_type', array_merge( $existing_post_types, ['post', 'page', 'tainacan-collection'], $collections_post_types ) ); - } else if ( isset($_GET['onlypages']) && $_GET['onlypages'] && $query->is_main_query() && $query->is_search() && ! is_admin() ) { - $query->set( 'post_type', 'pages' ); - } else if ( isset($_GET['onlyposts']) && $_GET['onlyposts'] && $query->is_main_query() && $query->is_search() && ! is_admin() ) { - $query->set( 'post_type', 'post' ); + $query->set( 'post_type', array_merge( $existing_post_types, ['post', 'page', 'tainacan-collection'], $collections_post_types ) ); + } else if ( isset($_GET['onlypages']) && $_GET['onlypages'] && $query->is_main_query() && $query->is_search() && ! is_admin() ) { + $query->set( 'post_type', 'pages' ); + } else if ( isset($_GET['onlyposts']) && $_GET['onlyposts'] && $query->is_main_query() && $query->is_search() && ! is_admin() ) { + $query->set( 'post_type', 'post' ); + } } } add_action( 'pre_get_posts', 'tainacan_include_items_in_search_results' );