First off, the get_comment_date( 'd\/m\/Y' )
resulted in a PHP notice in my case, so I changed that to get_comment_date( 'd\/m\/Y', $comment )
(i.e. I pass the $comment
object to the function).
Now the issue with your code is that the $result
should have a review
item with the value being an array of reviews (review objects):
$result = [
"@context" => "https://schema.org/",
"@type" => "Organization",
"name" => (get_the_title()),
"image" => (get_the_post_thumbnail_url(get_the_ID(), 'full')),
"aggregateRating" => [
...
],
'review' => $comlistall, // here, a "review" item must exists
/* Or something like so:
'review' => array(
array( "@type" => "Review", "headline" => ..., "reviewbody" => ..., ... ),
array( "@type" => "Review", "headline" => ..., "reviewbody" => ..., ... ),
...
),
*/
];
Secondly, your $comlistall
should produce an array which when it’s represented in JSON format, looks like the first one here (see the “Changed Text”).
So to fix the issue:
-
As I mentioned above, in the
$result
, use'review' => $comlistall
. -
Change this:
$c = [ "review" => [ "@type" => "Review", "headline" => (get_comment_meta($comment->comment_ID, WP_REVIEW_COMMENT_TITLE_METAKEY, true)), "reviewbody" => ($comment->comment_content), ... ] ]; $comlistall[] = $c;
to this (but you may assign the review data/object to the variable
$c
):$comlistall[] = [ "@type" => "Review", "headline" => (get_comment_meta($comment->comment_ID, WP_REVIEW_COMMENT_TITLE_METAKEY, true)), "reviewbody" => ($comment->comment_content), ... ];