first test on ajax
This commit is contained in:
@@ -83,4 +83,37 @@ class Partnerexpo_Core_Public {
|
||||
);
|
||||
}
|
||||
|
||||
public function register_endpoint() {
|
||||
register_rest_route('pexpo/v1', '/query', [
|
||||
'methods' => 'GET',
|
||||
'callback' => 'query_partners',
|
||||
'permission_callback' => '__return_true',
|
||||
]);
|
||||
}
|
||||
|
||||
function query_partners(WP_REST_Request $request) {
|
||||
$args = [
|
||||
'post_type' => 'pexpo_partners',
|
||||
'posts_per_page' => 15,
|
||||
'post_status' => 'publish',
|
||||
];
|
||||
|
||||
$query = new WP_Query($args);
|
||||
|
||||
$posts = [];
|
||||
|
||||
foreach ($query->posts as $post) {
|
||||
$posts[] = [
|
||||
'id' => $post->ID,
|
||||
'title' => $post->post_title,
|
||||
'slug' => $post->post_name,
|
||||
'url' => get_permalink($post),
|
||||
];
|
||||
}
|
||||
|
||||
wp_reset_postdata();
|
||||
|
||||
return rest_ensure_response($posts);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -90,14 +90,16 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
try {
|
||||
// REPLACE THIS URL with your actual endpoint
|
||||
// const response = await fetch(`/api/search?q=${encodeURIComponent(query)}&limit=${filters.maxResults}`);
|
||||
// const data = await response.json();
|
||||
const response = await fetch(`/pexpo/v1/query?q=${encodeURIComponent(query)}&limit=${filters.maxResults}`);
|
||||
const data = await response.json();
|
||||
|
||||
// --- SIMULATED FETCH FOR DEMO (Remove this block in production) ---
|
||||
await new Promise(r => setTimeout(r, 600)); // Fake network delay
|
||||
const data = simulateBackendResponse(query);
|
||||
// await new Promise(r => setTimeout(r, 600)); // Fake network delay
|
||||
// const data = simulateBackendResponse(query);
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
console.log(data);
|
||||
|
||||
results = data;
|
||||
|
||||
// 2. Compute local relevance if the API doesn't return it
|
||||
|
||||
Reference in New Issue
Block a user