Skip to content

Commit

Permalink
Fix meta search filter. Regression of 247.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcelloPerathoner committed Apr 10, 2024
1 parent b9278c5 commit 12d1808
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
11 changes: 5 additions & 6 deletions plugins/cap-meta-search/class-meta-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/',
Expand All @@ -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 ();
Expand Down
9 changes: 9 additions & 0 deletions themes/Capitularia/functions-include.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use cceh\capitularia\lib;

require 'class-cap-query.php';

const MAGIC_LOGIN = '#cap_login_menu#';

/**
Expand Down Expand Up @@ -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'];
}
}
3 changes: 1 addition & 2 deletions themes/Capitularia/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
5 changes: 1 addition & 4 deletions themes/Capitularia/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 12d1808

Please sign in to comment.