WordPress 自定义api

2021-03-22  本文已影响0人  lajunta

WordPress 中 自定义 rest api
在wp-content =>themes => 使用中的主题 =>functions.php 中 加入相关的代码

function hello( $data ) {
  return array(array("hello"=>"asfd","world"=>"dsfadsf"));
}

add_action( 'rest_api_init', function () {
  register_rest_route( 'iaa', '/news', array(
    'methods' => 'GET',
    'callback' => 'hello',
  ) );
} );

就可以访问 /wp-json/iaa/news

上一篇 下一篇

猜你喜欢

热点阅读