admin管理员组文章数量:1287126
I like to send specific data from a post to my JSON response in Wordpress. I like to send the output of the variable "hatus" to the JSON response, but it does not seem to work.
<?php
$hatus = "some information here";
echo wp_kses_post($hatus); ?>
And here is the code I am trying to send it to:
<?php
// Export API Data to JSON, another method
add_action('publish_post', function ($ID, $post) {
$wp_uri = get_site_url();
$customApiEndpoint = '/wp-json/wp/v2/posts'; // or your custom endpoint
$url = $wp_uri . $customApiEndpoint; // outputs
$response = wp_remote_get($url);
$responseData = json_encode($hatus); // saved under the wp root installation, can be customized to any folder
file_put_contents('your_api_data_backup.json', $responseData);
}, 10, 2);
?>
What am I doing wrong here? The only thing I want is to show that 'hatus' variable outcome in my JSON response. Can you help?
本文标签: phpSending simple variable on single page to WP JSON
版权声明:本文标题:php - Sending simple variable on single page to WP JSON 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741254203a2366357.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论