Improve identification of tax query term

This commit is contained in:
Cooper Dalrymple
2026-03-03 17:16:00 -06:00
parent 681e2ed152
commit 37572b5a8a

View File

@@ -300,13 +300,14 @@ final class Sort {
foreach ($wp_query->query['tax_query'] as $tax) { foreach ($wp_query->query['tax_query'] as $tax) {
if (!isset($tax['taxonomy'])) continue; if (!isset($tax['taxonomy'])) continue;
if ($current_relationship['taxonomy'] != $tax['taxonomy']) continue; if ($current_relationship['taxonomy'] != $tax['taxonomy']) continue;
$term_by = $tax['field']; $term_by = $tax['field'] ?? 'term_id';
$term_id = $tax['terms']; $term_id = $tax['terms'];
break; break;
} }
} else if ($current_relationship['taxonomy'] === 'category' && isset($wp_query->query['category_name'])) { } else if ($current_relationship['taxonomy'] === 'category' && isset($wp_query->query['category_name'])) {
$term_id = $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; if (empty($term_id)) return;
$term = get_term_by($term_by, $term_id, $current_relationship['taxonomy']); $term = get_term_by($term_by, $term_id, $current_relationship['taxonomy']);