admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('resource_filter_nonce') ]); } } public function renderFilterForm() { ob_start(); $template = rfGetTemplate('filter-form.php'); if ($template) { include_once $template; } else { echo '

Error: Template not found.

'; } $total_resources = wp_count_posts('resource')->publish; // Get the count of published resources ?>
Showing resources

Filters applied: None

loadResources(); ?>
'resource', 'posts_per_page' => -1, 'tax_query' => [], 's' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '', ]; $tax_query = []; if (!empty($_POST['resource_type'])) { $query_args['tax_query'][] = [ 'taxonomy' => 'resource_type', 'field' => 'slug', 'terms' => array_map('sanitize_text_field', $_POST['resource_type']), 'operator' => 'IN' ]; } if (!empty($_POST['resource_subject'])) { $query_args['tax_query'][] = [ 'taxonomy' => 'resource_subject', 'field' => 'slug', 'terms' => array_map('sanitize_text_field', $_POST['resource_subject']), 'operator' => 'IN' ]; } if (!empty($tax_query)) { $query_args['tax_query'] = [ 'relation' => 'AND', // Both filters must match ...$tax_query ]; } $query = new WP_Query($query_args); ob_start(); $resources = $query->posts; $template = rfGetTemplate('resource-results.php'); if ($template) { include_once $template; } else { echo '

Error: Results template not found.

'; } // Prepare response JSON $response = [ 'count' => $query->found_posts, 'filters' => [ 'search' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '', 'resource_type' => !empty($_POST['resource_type']) ? sanitize_text_field($_POST['resource_type']) : '', 'resource_subject' => !empty($_POST['resource_subject']) ? sanitize_text_field($_POST['resource_subject']) : '' ], 'html' => ob_get_clean() ]; echo json_encode($response); wp_die(); } public function loadResources() { $query_args = [ 'post_type' => 'resource', 'posts_per_page' => -1 ]; $query = new WP_Query($query_args); $resources = $query->posts; $template = rfGetTemplate('resource-results.php'); if ($template) { include_once $template; } else { echo '

Error: Results template not found.

'; } wp_reset_postdata(); } } new ResourceFilterPlugin();