feature: Filtering working as intended

This commit is contained in:
Keith Solomon
2025-02-04 13:44:36 -06:00
parent 5515b50fd7
commit c878c48e92
5 changed files with 151 additions and 74 deletions

26
templates/filter-form.php Normal file
View File

@@ -0,0 +1,26 @@
<?php
if (!defined('ABSPATH')) { exit; } // Prevent direct access
$resource_types = get_terms(['taxonomy' => 'resource_type', 'hide_empty' => true]);
$resource_subjects = get_terms(['taxonomy' => 'resource_subject', 'hide_empty' => true]);
?>
<form id="resource-filter">
<input type="text" id="search" name="search" placeholder="Search resources...">
<select id="resource_type" 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>
<select id="resource_subject" name="resource_subject">
<option value="">All Subjects</option>
<?php foreach ($resource_subjects as $subject) : ?>
<option value="<?php echo esc_attr($subject->slug); ?>"><?php echo esc_html($subject->name); ?></option>
<?php endforeach; ?>
</select>
<button type="submit">Filter</button>
</form>

View File

@@ -0,0 +1,15 @@
<?php
if (!defined('ABSPATH')) { exit; } // Prevent direct access
if (!empty($resources)) : ?>
<?php
foreach ($resources as $resource) :
$post_id = $resource->ID;
$post_title = get_the_title($post_id);
$post_link = get_permalink($post_id);
?>
<div class="resource-item"><a href="<?php echo esc_url($post_link); ?>"><?php echo esc_html($post_title); ?></a></div>
<?php endforeach; ?>
<?php else : ?>
<p>No resources found.</p>
<?php endif; ?>