I have built a display template and used the CSWP to show blog post comments and likes, however, being a CSWP it only updates once the search runs. I want the comments or likes to update immediately after someone posts a comment or a like. I have used spservices as below to return the comments and likes in "real time" but all my comment and post counts are appearing in the first item's commentsDIV. Any suggestions? Thanks in advance.
<!--#_
var itemID = ctx.CurrentItem.ListItemID;
var query = "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Number'>" + itemID + "</Value></Eq></Where></Query>";
$(document).ready(function() {
$().SPServices({
operation: "GetListItems",
async: false,
listName: "Posts",
CAMLQuery: query,
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='NumComments' /></ViewFields>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var commentCountVar = "<span>" + $(this).attr("ows_NumComments") + "</span>";
$("#commentsDIV").append(commentCountVar);
});
}
});
});
_#-->
<div id="commentsDIV"></div>