Issues Using get_the_ID() within mfunc
-
I am trying to load comments in a part of a page which is subject to page cache Disk. The rest of the page remains static, while comments can be posted and updated dynamically with each page load.
Assuming the principal would be straightforward, I have used the below code:
<!-- mfunc {hidden}-->
$arr = get_comments(array("post_id" => get_the_ID(),"status" => "approve",));
wp_list_comments( $args = array(), $arr);
<!-- /mfunc {hidden}-->However
get_the_ID()
doesn’t run. After a page cache purge, yes it does – the first load. Thereafter, once the page is cached, get_the_ID() no longer works.Instead, I then tried the following code, adding a queried object fetch
$obj = get_queried_object();
$id = $obj->ID;
$arr = get_comments(array("post_id" => $id,"status" => "approve",));Again, first load after page cache purge gets the right comments. Then subsequent reloads, it does nothing.
The Problem: Every comment is loaded, with the status
approve
suggesting the post_id is completely ignored because its empty.Is there something I am missing from the page cache mfunc fragment?
I’d rather use this than implement Ajax loading because I believe the comments to be beneficial on the page for SEO, and I may use them as a Q/A integrated into the ld+json schema.
Many thanks. On the link, under the “Ask” tab. FYI those comments shouldn’t even load. They’re not under that franchise CPT’s ID.
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.