Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress rest路由无法在页面模板上工作_Php_Wordpress - Fatal编程技术网

Php Wordpress rest路由无法在页面模板上工作

Php 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_

我试图实现的是,我希望在我的页面模板中显示用户,并具有搜索功能,为此,我正在进行ajax调用,该调用将发送搜索查询并触发路由,并根据该结果显示用户。由于某种原因,我不知道为什么我的休息路线找不到。下面是我的代码

//page-template.php

<?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){}
});