Skip to content

Instantly share code, notes, and snippets.

@alexdunae
Created June 1, 2017 18:40
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 alexdunae/d100974511ff57932f46f3a9204e5fc0 to your computer and use it in GitHub Desktop.
Save alexdunae/d100974511ff57932f46f3a9204e5fc0 to your computer and use it in GitHub Desktop.
<?php
add_action( 'rest_api_init', function () {
register_rest_route( 'salmon/v1', '/salmonnames', array(
'methods' => 'GET',
'callback' => 'get_salmon_names',
) );
} );
function get_salmon_names( $data ) {
global $wpdb;
$results = $wpdb->get_results( 'SELECT * FROM table', OBJECT );
$names = array();
foreach($results as $result) {
$names[] = $result->name;
}
return $names;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment