To be used in conjunction with the wordpress rest api plugin
https://wordpress.org/plugins/json-rest-api/
/* Polls Site */
<script>
function poll(poll_url, poll_timeout) {
setInterval( function() {
$.ajax({
dataType: "json",
url: poll_url,
success: function (data){
if(data.modified != date_modified){
if(!date_modified){
date_modified = data.modified;
}
else{
location.reload();
}
}
}
});
}, poll_timeout);
}
</script>
/*Refreshed page on page update*/
<script type="text/javascript">
var date_modified = null; poll("<?php echo site_url() ?>/wp-json/wp/v2/<?php echo $post->post_type ?>s/<?php echo $post->ID ?>", 3000);
</script>
Initially this was to be used with the Rest API plugin but Rest is native now with WP so you don't need the plugin anymore.
3 Responses
Write a comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.