宇讯一资源

vue组合wp-rest-api

发布于2022年01月10日 | 暂无评论 | 67阅读 | 其它

一、
1, functions.php
function get_menu() {

Change 'menu' to your own navigation slug.

return wp_get_nav_menu_items('menu');

}

add_action( 'rest_api_init', function () {
register_rest_route( 'myroutes', '/menu', array(
'methods' => 'GET',
'callback' => 'get_menu',
) );
} );
2,
For the example above you would access the data from:

http://your-domain.dev/wp-json/myroutes/menu
axios.get('https://www.kangertech.com/wp-json/myroutes/menu')
You can use the above method to create any routes you like to get any type of data that is not available in the WP Rest. Also good if you need to process some data before sending it to your application.
源:https://wordpress.stackexchange.com/questions/209381/get-wp-navigation-menu-from-rest-api-v2

暂无评论

发布评论