How to check if new posts have been published since page load?
My aim is to use the Heartbeat API to check if new posts have been published since the blog's homepage was loaded. If new posts have been published, I will display a link at the top of the screen "16 new posts" which, when clicked, will insert the new posts into the DOM.
My problem:
How can I check if new posts have been published since the blog's homepage was loaded?
My PHP so far:
function new_post_check( $response, $data, $screen_id ) {
// Do some processing here.
// Respond.
return $response;
}
add_filter( 'heartbeat_received', 'new_post_check', 10, 3 );
add_filter( 'heartbeat_nopriv_received', 'new_post_check', 10, 3 );
My script so far:
$( document ).on( 'heartbeat-tick.poll', function( event, data ) {
// Print data to the console.
console.log( data );
});
Topic heartbeat-api php Wordpress
Category Web