do_shortcode doesn’t work without hack
-
Hi Aaron,
We use your plugin and it usually works fine.
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.
But, although it shows the reviews, the aggregate shows 0 results and a 0 in the score ??
This has to do with the bold part of your function below:
function get_aggregate_reviews($postid) {
global $wpdb;$query = $wpdb->prepare(”
SELECT
COUNT(*) AS aggregate_count, AVG(tmp2.rating) AS aggregate_rating
FROM (
SELECT pm4.meta_value AS rating
FROM (
SELECT DISTINCT pm2.post_id
FROM {$wpdb->prefix}posts p1
INNER JOIN {$wpdb->prefix}postmeta pm1 ON pm1.meta_key = ‘wpcr3_enable’ AND pm1.meta_value = ‘1’ AND pm1.post_id = p1.id
INNER JOIN {$wpdb->prefix}postmeta pm2 ON pm2.meta_key = ‘wpcr3_review_post’ AND pm2.meta_value = p1.id
WHERE p1.id = %d
) tmp1
INNER JOIN {$wpdb->prefix}posts p2 ON p2.id = tmp1.post_id AND p2.post_status = ‘publish’ AND p2.post_type = ‘wpcr3_review’
INNER JOIN {$wpdb->prefix}postmeta pm4 ON pm4.post_id = p2.id AND pm4.meta_key = ‘wpcr3_review_rating’ AND pm4.meta_value IS NOT NULL AND pm4.meta_value != ‘0’
GROUP BY p2.id
) tmp2
“, intval($postid));
$results = $wpdb->get_results($query);$rtn = new stdClass();
if (count($results)) {
$rtn->aggregate_count = $results[0]->aggregate_count;
$rtn->aggregate_rating = $results[0]->aggregate_rating;
if ($rtn->aggregate_count == 0) { $rtn->aggregate_rating = 0; }
$rtn->stars = $this->get_rating_template($rtn->aggregate_rating, false);
}return $rtn;
}So, when leaving the bold part out, all works fine.
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?
Otherwise, with each update, we’d have to change this manually and that is bound to go wrong.
Hope you will find the time and if you need more clarification don’t hesitate to contact me.
Greets,
Olaf- This topic was modified 6 years, 7 months ago by .
- This topic was modified 6 years, 7 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘do_shortcode doesn’t work without hack’ is closed to new replies.