2017-03-03 51 views
0

在wordpress中,我添加了不同的自定义文件不同的帖子。当我请求帖子(/ wp-json/wp/v2/posts)时,没有自定义字段值我应该怎么做才能获得自定义字段?如何在wordpress中申请帖子时获得自定义文件的值?

+0

有自定义字段添加到的API,用于REST API可以使用自定义的前进方法域扩展插件推进的 – Lasantha

+0

REST API默认情况下不提供自定义字段自定义字段。但是,您可以通过修改回复将它们添加到您的网站。选中此项:https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/ –

回答

0

你应该试试这个!

<?php 
     $custom_fields = get_post_custom(72); 
     $my_custom_field = $custom_fields['my_custom_field']; 
     foreach ($my_custom_field as $key => $value) { 
      echo $key . " => " . $value . "<br />"; 
     } 
?> 

或了解更多参考:您可以访问https://codex.wordpress.org/Function_Reference/get_post_custom

感谢, Jenish。

相关问题