fix(admin): replicate reference advanced-filter settings page 1:1
- Rewrite post_list/filter schema (PHP + JS) with the reference theme's
field set, order, defaults and dependencies; topics fields excluded
(no topics taxonomy), AKSRT private filter_* toggles dropped
- Support dynamic checkbox options in AksField (options as formData key)
so cat_custom_filter.custom_filters lists the custom_filter dimensions
- Map PostDisplay filter settings to the new keys without legacy fallback;
cat_custom_filter now carries lists/dropdown fieldsets and array filters
- Wire the archive chain to reference semantics: cat_custom_filter
overrides per-category filter projects, custom_filter_show gates the
default display, dimension chip groups render on category/tag archives
- Filter archive queries (main query + AJAX endpoint) by _aksrt_cf_{key}
meta with exact-quoted LIKE matching
- Add advanced-filter settings reference contract test
This commit is contained in:
1 parent
4d6b2c6045
commit
a8060fa71d
16 files changed
+635
-154
No files matched your search
+65
-8
@@ -104,21 +104,54 @@ class TermMeta {
|
||||
$description = (string) $term->description;
|
||||
}
|
||||
|
||||
// 高级筛选(参考主题 zib-category.php 语义):cat 页按 cat_custom_filter 全量覆盖
|
||||
// 筛选项目,未匹配或 tag 页回退默认配置,custom_filter_show 决定自定义筛选显示。
|
||||
$page = $taxonomy === 'post_tag' ? 'tag' : 'cat';
|
||||
$custom_filter = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::get_archive_custom_filter_config((int) $term->term_id, $page)
|
||||
: ['custom_enabled' => false, 'custom_filters' => 'all', 'overrides' => []];
|
||||
$overrides = is_array($custom_filter['overrides'] ?? null) ? $custom_filter['overrides'] : [];
|
||||
|
||||
$ajax_category_enabled = !empty($global['ajax_category_enabled']);
|
||||
$ajax_category = is_array($global['ajax_category'] ?? null) ? $global['ajax_category'] : [];
|
||||
$ajax_tag_enabled = !empty($global['ajax_tag_enabled']);
|
||||
$ajax_tag = is_array($global['ajax_tag'] ?? null) ? $global['ajax_tag'] : [];
|
||||
$orderby_enabled = !empty($global['orderby_enabled']);
|
||||
$orderby_option = is_array($global['orderby_option'] ?? null) ? $global['orderby_option'] : [];
|
||||
if (array_key_exists('cat_s', $overrides)) {
|
||||
$ajax_category_enabled = !empty($overrides['cat_s']);
|
||||
$ajax_category = is_array($overrides['cat_lists'] ?? null) ? $overrides['cat_lists'] : $ajax_category;
|
||||
}
|
||||
if (array_key_exists('tag_s', $overrides)) {
|
||||
$ajax_tag_enabled = !empty($overrides['tag_s']);
|
||||
$ajax_tag = is_array($overrides['tag_lists'] ?? null) ? $overrides['tag_lists'] : $ajax_tag;
|
||||
}
|
||||
if (array_key_exists('orderby_s', $overrides)) {
|
||||
$orderby_enabled = !empty($overrides['orderby_s']);
|
||||
$orderby_option = is_array($overrides['orderby_lists'] ?? null) ? $overrides['orderby_lists'] : $orderby_option;
|
||||
}
|
||||
$orderby = sanitize_key((string) ($orderby_option['lists'][0] ?? $global['orderby'] ?? 'date'));
|
||||
|
||||
$filter_all = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_post_filter_settings() : [];
|
||||
|
||||
return [
|
||||
'taxonomy' => $taxonomy,
|
||||
'header_style' => $header_style,
|
||||
'show_sidebar' => $sidebar_enabled,
|
||||
'show_cover' => $header_style === 'cover' && !empty($global['cover_enabled']) && $cover_url !== '',
|
||||
'show_desc' => $taxonomy === 'post_tag' ? $description !== '' : (!empty($global['desc_enabled']) && $description !== ''),
|
||||
'filter_bar' => !empty($global['filter_bar']),
|
||||
'filter_bar' => !empty($global['filter_bar']) || $ajax_category_enabled || $ajax_tag_enabled || $orderby_enabled || !empty($custom_filter['custom_enabled']),
|
||||
'post_count' => !empty($global['post_count']),
|
||||
'orderby_enabled' => !empty($global['orderby_enabled']),
|
||||
'orderby' => sanitize_key((string) ($global['orderby'] ?? 'date')),
|
||||
'orderby_option'=> is_array($global['orderby_option'] ?? null) ? $global['orderby_option'] : [],
|
||||
'ajax_category_enabled' => !empty($global['ajax_category_enabled']),
|
||||
'ajax_tag_enabled' => !empty($global['ajax_tag_enabled']),
|
||||
'ajax_category' => is_array($global['ajax_category'] ?? null) ? $global['ajax_category'] : [],
|
||||
'ajax_tag' => is_array($global['ajax_tag'] ?? null) ? $global['ajax_tag'] : [],
|
||||
'orderby_enabled' => $orderby_enabled,
|
||||
'orderby' => $orderby,
|
||||
'orderby_option'=> $orderby_option,
|
||||
'ajax_category_enabled' => $ajax_category_enabled,
|
||||
'ajax_tag_enabled' => $ajax_tag_enabled,
|
||||
'ajax_category' => $ajax_category,
|
||||
'ajax_tag' => $ajax_tag,
|
||||
'custom_filter_enabled' => !empty($custom_filter['custom_enabled']),
|
||||
'custom_filter_keys' => $custom_filter['custom_filters'] ?? 'all',
|
||||
'custom_dimensions' => is_array($filter_all['custom_filter'] ?? null) ? $filter_all['custom_filter'] : [],
|
||||
'per_page' => max(4, min(48, (int) ($global['per_page'] ?? 12))),
|
||||
'cover_url' => $cover_url,
|
||||
'description' => $description,
|
||||
@@ -178,6 +211,30 @@ class TermMeta {
|
||||
$query->set('tax_query', $tax_query);
|
||||
}
|
||||
|
||||
// 自定义高级筛选维度 meta 过滤(参考主题 zib_sift_posts_per_page:meta_query LIKE;
|
||||
// meta 值为序列化数组,用带引号精确匹配避免前缀误命中)。
|
||||
if (!empty($settings['custom_filter_enabled'])) {
|
||||
$keys = $settings['custom_filter_keys'];
|
||||
$meta_query = is_array($query->get('meta_query')) ? $query->get('meta_query') : [];
|
||||
foreach ((array) ($settings['custom_dimensions'] ?? []) as $dimension) {
|
||||
$dim_key = sanitize_key((string) ($dimension['key'] ?? ''));
|
||||
if ($dim_key === '' || empty($_GET[$dim_key])) {
|
||||
continue;
|
||||
}
|
||||
if ($keys !== 'all' && !in_array($dim_key, (array) $keys, true)) {
|
||||
continue;
|
||||
}
|
||||
$meta_query[] = [
|
||||
'key' => '_aksrt_cf_' . $dim_key,
|
||||
'value' => '"' . sanitize_key(wp_unslash((string) $_GET[$dim_key])) . '"',
|
||||
'compare' => 'LIKE',
|
||||
];
|
||||
}
|
||||
if ($meta_query !== []) {
|
||||
$query->set('meta_query', $meta_query);
|
||||
}
|
||||
}
|
||||
|
||||
$orderby = isset($_GET['orderby']) ? sanitize_key(wp_unslash((string) $_GET['orderby'])) : 'date';
|
||||
$allowed = class_exists('\AKSRT\Settings\Settings')
|
||||
? \AKSRT\Settings\Settings::homepage_allowed_sorts()
|
||||
|
||||
Reference in new issue
Block a user