S
S
serega 20702020-08-27 18:43:49
RESTful API
serega 2070, 2020-08-27 18:43:49

How to make taxonomy assignment selection on request to rest api?

Hello guys, I'm doing such a thing, in general I have some kind of taxonomy based on tags in wordpress, in the fucntion.php file of the theme I have the following code:

function get_tags_swagger( WP_REST_Request $request ){

  $result = wp_remote_request('http://swagger/v1.0/tags?term=' .  $request['query_term']  ); // urlencode
  
    if( empty( $result ) ){
        return new WP_Error( 'no_author_posts', 'Записей не найдено', [ 'status' => 404 ] );
    }
  return json_decode($result['body']);	
}

add_action( 'rest_api_init', function(){	
  register_rest_route( 'swagger', '/tags/(?P<query_term>[\S-]+)', [
    'methods'  => 'GET',
    'callback' => 'get_tags_swagger',
  ] );

} );


which generally returns when requesting http://localhost/wp-json/swagger/tags/ to some json with all the tags starting with the letter "k", and now I'm thinking how it is possible to link it in the admin panel so that when typing, it gives out a list of tags that you can choose, in the admin panel this field is displayed through the acf plugin in the post, now yes there it gives out pre-set tags, but you need it as I described, tell me where to dig?
5f47d486d1641219830363.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Lopatin, 2020-08-28
@ClipClock08

In the admin panel, use jqury to pull this method with ajax, and append the result to your acf field. You will have an empty acf field in which you will append the result. Just bind xs as best, if through the key it will be necessary to do export and import of the field during transfers so that nothing breaks

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question