{"id":10546874,"date":"2018-08-01T09:58:38","date_gmt":"2018-08-01T09:58:38","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/do-shortcode-doesnt-work-without-hack\/"},"modified":"2018-08-01T10:00:37","modified_gmt":"2018-08-01T10:00:37","slug":"do-shortcode-doesnt-work-without-hack","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/do-shortcode-doesnt-work-without-hack\/","title":{"rendered":"do_shortcode doesn&#8217;t work without hack"},"content":{"rendered":"<p>Hi Aaron,<\/p>\n<p>We use your plugin and it usually works fine.<\/p>\n<p>Though on our website Sneakerwijzer.nl, which uses a custom theme, we could not get it to work properly with the standard settings. So our developer used the WP-standard do_shortcode option to show the reviews on the page.<\/p>\n<p>But, although it shows the reviews, the aggregate shows 0 results and a 0 in the score \ud83d\ude09<\/p>\n<p>This has to do with the bold part of your function below:<\/p>\n<p>function get_aggregate_reviews($postid) {<br \/>\n                               global $wpdb;<\/p>\n<p>                               $query = $wpdb-&gt;prepare(&#8221;<br \/>\n                                               SELECT<br \/>\n                                               COUNT(*) AS aggregate_count, AVG(tmp2.rating) AS aggregate_rating<br \/>\n                                               FROM (<br \/>\n                                                               SELECT pm4.meta_value AS rating<br \/>\n                                                               FROM (<br \/>\n                                                                               SELECT DISTINCT pm2.post_id<br \/>\n                                                                               FROM {$wpdb-&gt;prefix}posts p1<br \/>\n                                                                               INNER JOIN {$wpdb-&gt;prefix}postmeta pm1 ON <strong>pm1.meta_key = &#8216;wpcr3_enable&#8217; AND<\/strong> pm1.meta_value = &#8216;1&#8217; AND pm1.post_id = p1.id<br \/>\n                                                                               INNER JOIN {$wpdb-&gt;prefix}postmeta pm2 ON pm2.meta_key = &#8216;wpcr3_review_post&#8217; AND pm2.meta_value = p1.id<br \/>\n                                                                               WHERE p1.id = %d<br \/>\n                                                               ) tmp1<br \/>\n                                                               INNER JOIN {$wpdb-&gt;prefix}posts p2 ON p2.id = tmp1.post_id AND p2.post_status = &#8216;publish&#8217; AND p2.post_type = &#8216;wpcr3_review&#8217;<br \/>\n                                                               INNER JOIN {$wpdb-&gt;prefix}postmeta pm4 ON pm4.post_id = p2.id AND pm4.meta_key = &#8216;wpcr3_review_rating&#8217; AND pm4.meta_value IS NOT NULL AND pm4.meta_value != &#8216;0&#8217;<br \/>\n                                                               GROUP BY p2.id<br \/>\n                                               ) tmp2<br \/>\n                               &#8220;, intval($postid));<br \/>\n                               $results = $wpdb-&gt;get_results($query);<\/p>\n<p>                               $rtn = new stdClass();<\/p>\n<p>                               if (count($results)) {<br \/>\n                                               $rtn-&gt;aggregate_count = $results[0]-&gt;aggregate_count;<br \/>\n                                               $rtn-&gt;aggregate_rating = $results[0]-&gt;aggregate_rating;<br \/>\n                                               if ($rtn-&gt;aggregate_count == 0) { $rtn-&gt;aggregate_rating = 0; }<br \/>\n                                               $rtn-&gt;stars = $this-&gt;get_rating_template($rtn-&gt;aggregate_rating, false);<br \/>\n                               }<\/p>\n<p>                               return $rtn;<br \/>\n                }<\/p>\n<p>So, when leaving the bold part out, all works fine. <\/p>\n<p>Would it be possible for you to change the code so that, just in case of using the do_shortcode in a template and the checkbox on the page is off, the aggregates are still showing correctly?<\/p>\n<p>Otherwise, with each update, we&#8217;d have to change this manually and that is bound to go wrong.<\/p>\n<p>Hope you will find the time and if you need more clarification don&#8217;t hesitate to contact me.<\/p>\n<p>Greets,<br \/>\nOlaf<\/p>\n","protected":false},"template":"","class_list":["post-10546874","topic","type-topic","status-publish","hentry","topic-tag-shortcode"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10546874","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":2,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10546874\/revisions"}],"predecessor-version":[{"id":10546886,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/10546874\/revisions\/10546886"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=10546874"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}