🖥️ wip: Homepage search taxonomy configuration

This commit is contained in:
Keith Solomon
2025-02-13 21:33:00 -06:00
parent c79becb430
commit 4ec92a6014
4 changed files with 82 additions and 19 deletions

View File

@@ -0,0 +1,20 @@
<?php if (!defined('ABSPATH')) { exit; } ?>
<form class="flex w-full" id="homepage-filter" action="<?php echo site_url('/browse-resources/'); ?>" method="POST">
<?php
$resource_types = get_terms(['taxonomy' => 'resource_type']);
if (!empty($resource_types)) :
?>
<select class="w-fit" name="resource_type">
<option value="">All Types</option>
<?php foreach ($resource_types as $type) : ?>
<option value="<?php echo esc_attr($type->slug); ?>"><?php echo esc_html($type->name); ?></option>
<?php endforeach; ?>
</select>
<?php endif; ?>
<input class="full-width" type="text" name="search" placeholder="Search resources...">
<button class="btn btn-primary" type="submit">Search</button>
</form>

View File

@@ -1,20 +1,35 @@
<?php if (!defined('ABSPATH')) { exit; } ?>
<?php
if (!defined('ABSPATH')) { exit; } // Prevent direct access
<form class="flex w-full" id="homepage-filter" action="<?php echo site_url('/browse-resources/'); ?>" method="POST">
<?php
$resource_types = get_terms(['taxonomy' => 'resource_type']);
$homepage_taxonomy = isset($GLOBALS['homepage_taxonomy']) ? $GLOBALS['homepage_taxonomy'] : '';
if (!empty($resource_types)) :
?>
<select class="w-fit" name="resource_type">
<option value="">All Types</option>
<?php foreach ($resource_types as $type) : ?>
<option value="<?php echo esc_attr($type->slug); ?>"><?php echo esc_html($type->name); ?></option>
<?php endforeach; ?>
</select>
if (!empty($homepage_taxonomy)) :
$taxonomy_obj = get_taxonomy($homepage_taxonomy);
$terms = get_terms(['taxonomy' => $homepage_taxonomy, 'hide_empty' => true]);
if (!empty($taxonomy_obj) && !empty($terms)) : ?>
<form id="homepage-filter">
<!-- Search Field -->
<div class="search-text">
<input class="full-width" type="text" id="search" name="search" placeholder="Search resources..." value="<?php echo isset($search) ? esc_attr($search) : ''; ?>">
<button type="reset" id="clear-search">&times;</button>
<button type="submit">Search</button>
</div>
<!-- Single Taxonomy Filter -->
<div class="search-tax">
<details class="taxonomy-filter" data-taxonomy="<?php echo esc_attr($homepage_taxonomy); ?>">
<summary><?php echo esc_html($taxonomy_obj->labels->singular_name); ?></summary>
<div class="filter-options">
<?php foreach ($terms as $term) : ?>
<label>
<input type="checkbox" name="<?php echo esc_attr($homepage_taxonomy); ?>[]" value="<?php echo esc_attr($term->slug); ?>">
<?php echo esc_html($term->name); ?>
</label>
<?php endforeach; ?>
</div>
</details>
</div>
</form>
<?php endif; ?>
<input class="full-width" type="text" name="search" placeholder="Search resources...">
<button class="btn btn-primary" type="submit">Search</button>
</form>
<?php endif; ?>