Created
October 21, 2021 04:01
-
-
Save tjkhara/c208a58ed24a5414f13a1f7c5241a7d3 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
<?php | |
add_action('rest_api_init', 'getawayRegisterRoute'); | |
function getawayRegisterRoute() { | |
register_rest_route( 'getaway/v1', 'data', array( | |
'methods' => WP_REST_SERVER::READABLE, | |
'callback' => 'getawayDataResults' | |
)); | |
} | |
function getawayDataResults() { | |
$getaways = new WP_Query(array( | |
'post_type' => 'lodging-getaways', | |
'posts_per_page' => 10 | |
)); | |
$getawayResults = array(); | |
while($getaways->have_posts()) { | |
$getaways->the_post(); | |
array_push($getawayResults, array( | |
'title' => get_the_title(), | |
'permalink' => get_the_permalink(), | |
'imageLink' => get_the_post_thumbnail_url( get_the_ID(), 'large' ) | |
)); | |
} | |
return $getawayResults; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment