2017-02-19 152 views
0

我想输出WP Job Manager插件的job_listing的自定义字段。 我试过这个帖子:https://wordpress.org/support/topic/rest-api-integration-with-wp-job-manager/而且这个字段总是为空。如何在Wordpress中为自定义帖子类型显示JSON响应中的自定义字段?

我试图返回一个硬编码的字符串,但该字段再次为空。

add_action('rest_api_init', function() { 
    register_rest_field('job_listing', 'geolocation_city', array(
     'get_callback' => function($job_listing) { 
      return "YO"; 
     }, 
     'update_callback' => null, 
     'schema' => null 
    )); 
}); 

enter image description here

回答

0

我已经找到了解决办法。我需要指定模式使其工作:

add_action('rest_api_init', function() { 
    register_rest_field('job_listing', 'geolocation_city', array(
     'get_callback' => function($job_listing) { 
      return 'YO'; 
     }, 
     'update_callback' => null, 
     'schema' => array(
      'description' => __('Some'), 
      'type'  => 'string' 
     ), 
    )); 
}); 
+0

请标记您的答案,如果解决了问题 –

相关问题