From 12d1808b5e36a1f631fb6573eb16817be295c99d Mon Sep 17 00:00:00 2001 From: Marcello Perathoner Date: Wed, 10 Apr 2024 11:56:59 +0200 Subject: [PATCH] Fix meta search filter. Regression of 247. --- plugins/cap-meta-search/class-meta-search.php | 11 +++++------ themes/Capitularia/functions-include.php | 9 +++++++++ themes/Capitularia/functions.php | 3 +-- themes/Capitularia/search.php | 5 +---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/plugins/cap-meta-search/class-meta-search.php b/plugins/cap-meta-search/class-meta-search.php index 7a5cc5bc..2c269431 100644 --- a/plugins/cap-meta-search/class-meta-search.php +++ b/plugins/cap-meta-search/class-meta-search.php @@ -41,12 +41,11 @@ public function on_pre_get_posts ($query) { // don't interfere with standard Wordpress query if (is_meta_search () && $query->is_main_query ()) { - $meta_query_args = array (); - $query->query['status'] = current_user_can ('read_private_pages') ? 'private' : 'publish'; - // The metadata is kept on the API server, so reflect the query - // there. + // The metadata is kept on the API server, so reflect the query there. This + // is the same query as in the browser location bar, plus the status + // parameter. $this->json = lib\api_json_request ( '/data/query_manuscripts.json/', @@ -67,12 +66,12 @@ function ($item) { // The data server already did all the heavy lifting for us. // The Wordpress query only has to filter the manuscripts by // tei-xml-id. - $meta_query_args[] = array ( + $meta_query_args = array (array ( 'key' => 'tei-xml-id', 'value' => $xml_ids, 'compare' => 'IN', 'type' => 'CHAR' - ); + )); $query->set ('meta_query', $meta_query_args); $query->query_vars['search_terms'] = array (); diff --git a/themes/Capitularia/functions-include.php b/themes/Capitularia/functions-include.php index ac591136..7fbd005d 100644 --- a/themes/Capitularia/functions-include.php +++ b/themes/Capitularia/functions-include.php @@ -13,6 +13,8 @@ use cceh\capitularia\lib; +require 'class-cap-query.php'; + const MAGIC_LOGIN = '#cap_login_menu#'; /** @@ -696,5 +698,12 @@ function cap_rest_user_info (\WP_REST_Request $request) function on_after_setup_theme () { + // disable widgets block editor remove_theme_support ('widgets-block-editor'); + + // use our custom query class that collapses whitespace in the search data + if (!is_admin()) { + $GLOBALS['wp_the_query'] = new \cceh\capitularia\theme\CapQuery(); + $GLOBALS['wp_query'] = $GLOBALS['wp_the_query']; + } } diff --git a/themes/Capitularia/functions.php b/themes/Capitularia/functions.php index 90399a96..7f133419 100644 --- a/themes/Capitularia/functions.php +++ b/themes/Capitularia/functions.php @@ -68,8 +68,7 @@ add_action ('admin_enqueue_scripts', ns ('on_admin_enqueue_scripts')); add_action ('registered_post_type', ns ('on_registered_post_type'), 10, 2); add_action ('pre_get_posts', ns ('on_pre_get_posts')); -/* disable widgets block editor */ -add_action ('after_setup_theme', ns ('on_after_setup_theme')); +add_action ('after_setup_theme', ns ('on_after_setup_theme'), 1, 0); add_action ( 'rest_api_init', diff --git a/themes/Capitularia/search.php b/themes/Capitularia/search.php index 810e1146..ebfbe60e 100644 --- a/themes/Capitularia/search.php +++ b/themes/Capitularia/search.php @@ -8,14 +8,11 @@ namespace cceh\capitularia\theme; -require 'class-cap-query.php'; - get_header (); get_main_start ('search-php'); -// use our custom query class that collpases whitespace in the search data -$cap_query = new CapQuery ($wp_query->query); +$cap_query = $GLOBALS['wp_the_query']; /* * Build the "You searched for ..." message