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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user