Created
April 23, 2020 17:12
-
-
Save mager19/2ccc7a60dac21f241c02d2df05519b40 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getTeamMembers() | |
{ | |
$args = array('post_type' => 'team', 'posts_per_page' => -1); | |
// Run a custom query | |
$loop = new WP_Query($args); | |
if ($loop->have_posts()) { | |
$i = 0; | |
$data = array(); | |
while ($loop->have_posts()) { | |
$loop->the_post(); | |
$data[$i]['title'] = get_the_title(); | |
$data[$i]['excerpt'] = get_the_excerpt(); | |
$i++; | |
} | |
// Return the data | |
return $data; | |
} | |
} | |
//Add the makes endpoint | |
add_action('rest_api_init', function () { | |
register_rest_route('gallery/v1', '/post-gallery', array( | |
'methods' => 'GET', | |
'callback' => 'getTeamMembers', | |
)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment