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