Can u reproduce this on a fresh install of WP with just this plugin? Because I don’t see how can that happen. Unless some plugin overwrites the custom field of this post.
The ratings are stored in the custom field. So the moment you click edit post the ratings stops there. Once the post is edited and u click save, the post ratings will go back to the original value which should not be 0.
The only reason why it is 0, is some plugin manually overwrite the custom field to have 0.
As mentioned in the link you pasted. I am quite sure some plugin is messing around with the custom fields of a post.
Dear Lester,
i’ve tested it on a fresh install already. It works perfectly.
I think you are totally right if you say it is a custom field error.
Our theme use a lot of custom fields.
But I have to ask you:
Could you please add this Fix to the next release, or a fix like that? I mean the fix works great and improve your code for all users, who using a theme with custom fields. Is it perhaps possible?
The fixed Code look like this:
### Function: Add Rating Custom Fields
add_action('transition_post_status', 'add_ratings_fields', 10, 4);
function add_ratings_fields($new_status, $old_status, $post) {
global $wpdb;
$post_ID = $post->ID;
if($new_status == "publish" && $old_status != "publish") {
add_post_meta($post_ID, 'ratings_users', 0, true);
add_post_meta($post_ID, 'ratings_score', 0, true);
add_post_meta($post_ID, 'ratings_average', 0, true);
}
}
It would be GREAT!!!
Best regards,
Lars
I am not too sure what are the side effects of using post transition to add post meta. To be honest, I have no idea why the conflicted plugin is clearing away the custom field. It doesn’t seem right though.