【发布时间】:2021-12-10 06:57:09
【问题描述】:
我喜欢将帖子中的特定数据发送到我在 Wordpress 中的 JSON 响应。我喜欢将变量“hatus”的输出发送到 JSON 响应,但它似乎不起作用。
<?php echo wp_kses_post($hatus); ?>
这是我要发送到的代码:
<?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 https://your-site.com/wp-json/wp/v2/posts
$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);
?>
我在这里做错了什么?我唯一想要的是在我的 JSON 响应中显示“hatus”变量结果。你能帮忙吗?
【问题讨论】: