wordpress - Limit wp-rest-api posts request to an array of postID's -


my complete project need return nearest-posts given geolocation.

i succeeded in doing building custom callback function seeking nearest posts building custom array containing data-fields of nearest posts. if define function callback function of route works great!

all ok return copy of default post-return, of course limited nearest posts. , not set of custom defined fields.

i can't seem figure out how this.

before going details know way go. plan, doesn't work, :

  • extend wp_rest_posts_controller
    • register (and initialize) new route
    • define custom callback function in new route
    • the custom callback function builds array of postid's nearest (lat&long passed in http request)

so far comes problem. how pass array of postids get_items method of wp_rest_posts_controller in order "default" return of specific(nearest) posts

clearly simple approach doesn't work

public function custom_callback_function($geoloc_array) {      // call function get_nearest_items($geoloc_array)      // returns array of postids'       //  : [163,49]      $nearest_poi_array = get_nearest_items($geoloc_array);      // put array of postids fetch in "include" of new array     // hand on new array get_items method of wp_rest_posts_controller      $posts_to_return['include'] = $nearest_poi_array;     return get_items($posts_to_return);  } 

if point me right direction grateful!!


Comments

Post a Comment

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -