
// Format and return JSON return array_map(function($post) return [ 'title' => get_the_title($post), 'url' => get_permalink($post), 'excerpt' => wp_trim_words($post->post_excerpt, 20) ]; , $query->posts);
For sites with >5,000 posts, indexed search is mandatory. Real-time will cause timeouts. 3. Database Impact (Benchmark Example) Tested on 50k posts, shared hosting (2GB RAM, 2 CPU): wordpress search plugin ajax
because they use WP_Query or $wpdb->prepare() . However, cheap plugins that build raw SQL are dangerous. Best Free AJAX Search Plugin Ivory Search (free version) – gives you AJAX live search + basic filters. No indexing, but fine for <2,000 posts. Database Impact (Benchmark Example) Tested on 50k posts,
let debounceTimer; searchInput.addEventListener('input', (e) => clearTimeout(debounceTimer); debounceTimer = setTimeout(() => fetch(`/wp-json/mytheme/v1/search?s=$encodeURIComponent(e.target.value)`) .then(res => res.json()) .then(renderResults); , 300); ); | Site Type | Recommended Plugin | Reason | |-----------|-------------------|--------| | Small blog (<1k posts) | Ivory Search (free) | Simple, zero config | | Medium blog / news | Relevanssi Premium | Best for text relevance | | WooCommerce store | Fibosearch (free or pro) | Blazing fast, respects stock | | Large custom site (20k+ posts, many fields) | SearchWP + Live Search | Indexes everything, highly tunable | | Budget, lots of custom post types | Ajax Search Pro (one-time $39) | One-time payment, many layouts | No indexing, but fine for <2,000 posts
$query = new WP_Query([ 's' => $s, 'posts_per_page' => 10, 'post_type' => ['post', 'page', 'product'] ]);