Skip to content

Instantly share code, notes, and snippets.

@AaronRutley
Last active November 16, 2016 01:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AaronRutley/0731518060e15f5003932bcce7c5df40 to your computer and use it in GitHub Desktop.
Save AaronRutley/0731518060e15f5003932bcce7c5df40 to your computer and use it in GitHub Desktop.
<?php
function ar_custom_project_endpoint($data) {
$args = array(
'posts_per_page' => -1,
'offset' => 0,
'category' => '',
'category_name' => '',
'orderby' => 'title',
'order' => 'ASC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'project',
'post_mime_type' => '',
'post_parent' => '',
'author' => '',
'post_status' => 'publish'
);
$items = get_posts( $args );
$data = array();
$response_data = array();
foreach($items as $post) {
$response_data['extension_name'] = $post->post_title;
$response_data['extension_link'] = get_field('link',$post->ID);
$response_data['extension_desc'] = get_field('description',$post->ID);
array_push($data,$response_data);
}
return new WP_REST_Response( $data, 200 );
}
add_action( 'rest_api_init', function () {
register_rest_route( 'wp/v2', '/featured-projects', array(
'methods' => 'GET',
'callback' => 'ar_custom_project_endpoint',
) );
} );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment