How the JS script works
-
On page load, the script loads the post comments by making an AJAX request to a custom WordPress REST API endpoint at
/tcm/v1/comments/<post ID>(here’s a sample URL, valid as of writing). -
Then the script displays the comments sorted by the
sort_fieldvalue in the comment localization parameters defined in thetcm_get_localization_parameters()(PHP) function. So at this point, your custom sort field (the metadata namedconfidence_rank_cached) would work as expected. -
However, it didn’t work when you selected the “Top Rated” option in the dropdown because the script (always) sets back the sort field to
comment_karma— see the relevant code below:sortComments: function (a) { switch (a) { ... case "top-rated": (this.collection.compField = "comment_karma"), (this.collection.compOrder = -1); } ... },
How to make your custom sort field works when the “Top Rated” option is selected
-
Change the above
comment_karmatoconfidence_rank_cached.Yes, modifying (core) plugin files is not recommended, but I don’t have enough time to look thoroughly on the plugin script. Hence it’s up to you to come up with a better solution than modifying the original JS file.
-
Add your custom metadata to the REST API endpoint mentioned above — and add the metadata as a root/top-level property (i.e. same level as the
comment_karmafield).I don’t know if the plugin provides a specific hook for filtering the comment objects/data in the REST API response, but you can try using the
get_commenthook to add the custom metadata to the comment object.