• Resolved hnwp

    (@hnwp)


    Hi all!

    I have this frustrating issue with the _wc_rating_count for one of my products.

    For some reason, the rating count is higher than the total review count.

    If you go to the URL above, scroll down to the reviews, and then inspect the rating bars, you see the .graph__wrapper divs have data attributes showing the
    data-rating: 1-5,
    data-rate: # of that star rating (which is wrong),
    data-count: total # of reviews

    I thought changing the wp_postmeta _wc_rating_count in the database would fix this–which it did momentarily–but then we got a new review and that refreshed the database with the incorrect values.

    How can I find these “ghost” comments? They’re not in the comments part of the admin dashboard.

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

Viewing 10 replies - 1 through 10 (of 10 total)
  • Thread Starter hnwp

    (@hnwp)

    Bump

    Are you talking about the 5 stars being at 109% and the others being at 2% and that not mathematically making sense? I see 41 reviews and it states 41 are there. But if you just got a new one and you expect to see 42 then did you approve that review already in the backend or it’s not there? A bit confused.

    Thread Starter hnwp

    (@hnwp)

    @serafinnyc Right, but the 41 count is fine. It’s the data-rate that’s wrong:

    The $product->get_rating_count(5) yields 45, even though the total review count is 41.

    I don’t know why the postmeta “_wc_rating_count” would be higher than the review count (“_wc_review_count”).

    <div class="graph__wrapper" data-rating="5" data-rate="45" data-count="41">
        <div class="graph-number">5 star</div>
        <div class="graph-bar">
            <span style="width: 109.75609756098%"></span>
        </div>
        <div class="graph-rating">109%</div>
    </div>

    Do you have any additional Schema running anywhere? Custom or Yoast?

    Thread Starter hnwp

    (@hnwp)

    Actually, yes. I have review schema. Would that interfere with the get_rating_count()? Does it matter where in the DOM it’s placed?

    (I also have regular product schema.)

    Yes. Yoast, WooCommerce they all have a default Schema.

    One could be overwriting the other. WooCommerce comes with Schema already built in. If you’re using a plugin to add additional Schema or a Custom Field it could be throwing things off.

    You can shut off Yoast’s Schema by adding this or they may have a check button now.

    function bybe_remove_yoast_json($data){
        $data = array();
        return $data;
      }
      add_filter('wpseo_json_ld_output', 'bybe_remove_yoast_json', 10, 1
    

    and to turn off WC’s for testing

    You can shut off WC’s Schema by adding this to your functions and testing after.

    function remove_output_structured_data() {
      remove_action( 'wp_footer', array( WC()->structured_data, 'output_structured_data' ), 10 ); // This removes structured data from all frontend pages
      remove_action( 'woocommerce_email_order_details', array( WC()->structured_data, 'output_email_structured_data' ), 30 ); // This removes structured data from all Emails sent by WooCommerce
    }
    add_action( 'init', 'remove_output_structured_data' );
    

    I’m pretty sure it’s still that way unless something’s changed which I haven’t heard or seen.

    Thread Starter hnwp

    (@hnwp)

    @serafinnyc I have created my own structured schema data, but I don’t think that’s the problem.

    I applied these functions, updated my data in postmeta, and then submitted a new review. The postmeta data still reverted to the old, inaccurate numbers.

    Somewhere in my wordpress database there’s a rating count that’s updating the postmeta, and it’s like 4-5 higher than it should be. I don’t think it’s schema-related.

    ah. okay then. sometimes if using JSON it can conflict. So I thought maybe that was happening.

    Thread Starter hnwp

    (@hnwp)

    @serafinnyc I found the issue (and thank you for all your help).

    Some comments, by human error, had multiple rating values.

    I had to sort through all the comments with the product and find ones whose meta rating was > 1

    if( count( get_comment_meta( $comment->comment_ID, 'rating' ) ) > 1 ) {
    print_r( get_comment_meta( $comment->comment_ID, 'rating' ) );
    }

    Then, I had to delete the comment meta and re-add it with the correct value by looping through each one.

    delete_comment_meta( $comment_ID, 'rating' );
    if ( ! metadata_exists( 'comment', $comment_ID, 'rating' ) ) {
    add_comment_meta( $comment_ID, 'rating', $number );
    }

    Once updating the page (as I hooked this to action ‘save_post’), everything was fixed.

    That’s the last time I manually tweak the post_meta!

    • This reply was modified 5 years, 10 months ago by hnwp. Reason: Misspelling

    Ah. That makes perfect sense. Glad you found it!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Rating Count Postmeta Incorrect in Database’ is closed to new replies.