Support » Plugin: WP Customer Reviews » do_shortcode doesn’t work without hack

  • Resolved ogessel

    (@ogessel)


    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 1 year, 3 months ago by ogessel.
    • This topic was modified 1 year, 3 months ago by ogessel.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • I am experiencing the exact same issue I believe. Ideally, I want to use the do_shortcode in my template so that I have more control over where it is outputted. The only issue is that the average ratings are 0 and reviews 0, when in fact there are reviews.

    If I remove the do_shortcode from my template and tick the checkbox on the page, everything works perfectly as expected. This is a great plugin and I want to continue to use it.

    @ogessel – Did you receive a response?

    Nope, no response. We stopped using the plugin so for us the issue doesn’t exist anymore.

    Hope you can get it resolved by them.

    Alternatively you have to change it yourself in their plugin but then you have to monitor that every update…

    Good luck!

    Plugin Author Aaron Queen

    (@bompus)

    This isn’t the official support forum, and I’ve never seen a ticket for this, so my apologies in the delay in responding here on the community forum.

    We’ll look into this. At the heart of the plugin, it works only for posts when the checkbox is clicked to enable reviews for that page/post. This is by design.

    However, I do see the use case of using do_shortcode to output the reviews on another page, without them outputting on the page they are assigned to. I’ll see what we can do to remedy the problem.

    It’s possible that we don’t need to include the wpcr3_enable condition in get_aggregate_reviews(), as it only pertains to a single postid. One of the reasons it is included is for performance on blogs with a massive amount of posts. However, filtering on a single postid should be the same either way, so I’ll put some thought into this.

    Thanks!

    Plugin Author Aaron Queen

    (@bompus)

    @ogessel @creative_lounge

    Alright, what you’re trying to attempt should now be possible in upcoming v3.2.2 , which should be released today.

    Previously, if the checkbox to enable WPCR on the page was not checked, you couldn’t see the fields to fill out for the business/product information. I’ve now allowed those fields to always display, allowing you to uncheck the Enable WPCR box, yet fill out the information that will be used if you do the hack to enable it via text shortcode or do_shortcode() functions.

    Great news, thx!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘do_shortcode doesn’t work without hack’ is closed to new replies.