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

    (@hnwp)

    Bump

    Stef

    (@serafinnyc)

    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>
    Stef

    (@serafinnyc)

    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.)

    Stef

    (@serafinnyc)

    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.

    Stef

    (@serafinnyc)

    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 7 years ago by hnwp. Reason: Misspelling
    Stef

    (@serafinnyc)

    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.