Created
June 1, 2017 18:40
-
-
Save alexdunae/d100974511ff57932f46f3a9204e5fc0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?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