From 681e2ed152feed10b9dd328d7466e67af3b4940e Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Tue, 3 Mar 2026 17:11:33 -0600 Subject: [PATCH 1/2] Prevent modifying query if term not found --- inc/class-sort.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inc/class-sort.php b/inc/class-sort.php index bfe27a0..ac3fad3 100644 --- a/inc/class-sort.php +++ b/inc/class-sort.php @@ -307,10 +307,10 @@ final class Sort { } else if ($current_relationship['taxonomy'] === 'category' && isset($wp_query->query['category_name'])) { $term_id = $wp_query->query['category_name']; } - if (empty($term_id)) break; + if (empty($term_id)) return; $term = get_term_by($term_by, $term_id, $current_relationship['taxonomy']); - if (!is_a($term, 'WP_Term')) break; + if (!is_a($term, 'WP_Term')) return; $wp_query->set('meta_key', "ogre-sort_{$current_relationship['taxonomy']}_{$term->term_id}"); $wp_query->set('orderby', 'meta_value_num'); -- 2.39.5 From 37572b5a8aa67f7635420860ffa6ae4706039e94 Mon Sep 17 00:00:00 2001 From: Cooper Dalrymple Date: Tue, 3 Mar 2026 17:16:00 -0600 Subject: [PATCH 2/2] Improve identification of tax query term --- inc/class-sort.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/class-sort.php b/inc/class-sort.php index ac3fad3..8a72c77 100644 --- a/inc/class-sort.php +++ b/inc/class-sort.php @@ -300,13 +300,14 @@ final class Sort { foreach ($wp_query->query['tax_query'] as $tax) { if (!isset($tax['taxonomy'])) continue; if ($current_relationship['taxonomy'] != $tax['taxonomy']) continue; - $term_by = $tax['field']; + $term_by = $tax['field'] ?? 'term_id'; $term_id = $tax['terms']; break; } } else if ($current_relationship['taxonomy'] === 'category' && isset($wp_query->query['category_name'])) { $term_id = $wp_query->query['category_name']; } + if (is_array($term_id)) $term_id = array_values($term_id)[0]; if (empty($term_id)) return; $term = get_term_by($term_by, $term_id, $current_relationship['taxonomy']); -- 2.39.5