'abddir_listing', 'post_status' => 'publish', 'posts_per_page' => $per_page, 'paged' => $paged, 'orderby' => 'title', 'order' => 'ASC', 'meta_query' => [[ 'key' => 'abddir_directory_id', 'value' => $dir_id, 'compare' => $dir_id ? '=' : 'EXISTS', ]], ]; if ( $search ) { $args['s'] = $search; } $query = new WP_Query($args); $html = ''; if ( $query->have_posts() ) { ob_start(); $template = $layout === 'list' ? abddir_PLUGIN_DIR . 'templates/list.php' : abddir_PLUGIN_DIR . 'templates/grid.php'; include $template; $html = ob_get_clean(); } else { $html = '

No listings found matching your search.

'; } wp_send_json_success([ 'html' => $html, 'total' => $query->found_posts, 'total_pages' => $query->max_num_pages, 'paged' => $paged, ]); } add_action('wp_ajax_abddir_filter_listings', 'abddir_ajax_filter_listings'); add_action('wp_ajax_nopriv_abddir_filter_listings', 'abddir_ajax_filter_listings');