If the wp_send_json()
function is sending the right data, but for some reason you want to use another function to actually send the JSON data, then you can use wp_json_encode()
. This is basically the only thing that wp_send_json()
does before sending off the data.
add_action( 'publish_post', 'wpse_228607_publish_post', 10, 2 );
function wpse_228607_publish_post( $post_id, $post ){
//* Do some stuff to get your $article variable
$encode = wp_json_encode( $article );
//* Do some stuff with the json encoded article
}
Make sure you’re sending the correct Content-Type and charset. wp_send_json()
takes care of that for you.