<?php // your arbitrary vars $rating = 1; $review_total = 100; $description = 'How do I not break json'; $heading_title = 'As above...'; $thumb = 'http://.../thumb.jpg'; $json = [ '@context' => 'http://schema.org', '@type' => 'Product', 'aggregateRating' => [ [ '@type' => 'AggregateRating', 'ratingValue' => $rating, 'reviewCount' => $review_total, ] ], 'description' => $description, 'name' => $heading_title, 'image' => $thumb, 'review' => [], ]; // query reviews from db $reviews = [ [ 'author' => 'Lawrence Cherone', 'date_added' => '11/11/17 00:00:00', 'text' => 'You should instead use json_encode', 'rating' => 1 ], ]; foreach ($reviews as $review) { $json['review'][] = [ '@type' => 'Review', 'author' => $review['author'], 'datePublished' => $review['date_added'], 'description' => '', 'name' => $review['author'], 'reviewRating' => [ '@type' => 'Rating', 'bestRating' => '5', 'ratingValue' => $review['rating'], 'worstRating' => '1', ], ]; } ?> <script type="application/ld+json"> <?= json_encode($json, JSON_PRETTY_PRINT) ?> </script>
You have javascript disabled. You will not be able to edit any code.