Php Wordpress rest路由无法在页面模板上工作
我试图实现的是,我希望在我的页面模板中显示用户,并具有搜索功能,为此,我正在进行ajax调用,该调用将发送搜索查询并触发路由,并根据该结果显示用户。由于某种原因,我不知道为什么我的休息路线找不到。下面是我的代码 //page-template.phpPhp Wordpress rest路由无法在页面模板上工作,php,wordpress,Php,Wordpress,我试图实现的是,我希望在我的页面模板中显示用户,并具有搜索功能,为此,我正在进行ajax调用,该调用将发送搜索查询并触发路由,并根据该结果显示用户。由于某种原因,我不知道为什么我的休息路线找不到。下面是我的代码 //page-template.php <?php function find_employee($request){ wp_send_json_success('FROM TEMPLATE'); die(); } add_action('rest_
<?php
function find_employee($request){
wp_send_json_success('FROM TEMPLATE');
die();
}
add_action('rest_api_init', function(){
register_rest_route( 'app/v1', '/findEmployee', [
'methods' => 'GET',
'callback' => 'find_employee'
]);
});
?>
$.ajax({
type: 'GET',
url: myAjax.restURL + 'app/v1/findEmployee',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-WP-Nonce', myAjax.nonce);
},
success: function(response){
if(response.success){
console.log('RESPONSE ',response);
}
},
error: function (xhr, ajaxOptions, thrownError) {},
complete: function(data){}
});