Skip to content

Instantly share code, notes, and snippets.

@mager19
Created April 23, 2020 17:12
Show Gist options
  • Save mager19/2ccc7a60dac21f241c02d2df05519b40 to your computer and use it in GitHub Desktop.
Save mager19/2ccc7a60dac21f241c02d2df05519b40 to your computer and use it in GitHub Desktop.
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