admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('resource_filter_nonce') ]); } } public function renderFilterForm() { ob_start(); ?>
'resource_type', 'hide_empty' => true]); $subjects = get_terms(['taxonomy' => 'resource_subject', 'hide_empty' => true]); ?>
loadResources(); ?>
'resource', 'posts_per_page' => -1, 'tax_query' => [], 's' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '', ]; if (!empty($_POST['resource_type']) || !empty($_POST['resource_subject'])) { $query_args['tax_query']['relation'] = 'AND'; // Ensures both must match if (!empty($_POST['resource_type'])) { $query_args['tax_query'][] = [ 'taxonomy' => 'resource_type', 'field' => 'slug', 'terms' => sanitize_text_field($_POST['resource_type']) ]; } if (!empty($_POST['resource_subject'])) { $query_args['tax_query'][] = [ 'taxonomy' => 'resource_subject', 'field' => 'slug', 'terms' => sanitize_text_field($_POST['resource_subject']) ]; } } error_log(print_r($query_args, true)); // Add this to debug query args $this->loadResources($query_args); wp_die(); } private function loadResources($query_args = ['post_type' => 'resource', 'posts_per_page' => -1]) { $query = new WP_Query($query_args); if ($query->have_posts()) { echo ''; } else { echo '

No resources found.

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