Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Recently i activated debug mode on my wordpress blog and the following error occurred .

 Notice: Undefined index: ratings_users in C:\wamp\...\wp-postratings.php on line 994

The code is :

if(is_null($post_ratings_data)) {
    $post_ratings_data = get_post_custom($post_id);
    **$post_ratings_users = intval($post_ratings_data['ratings_users'][0]);**
    $post_ratings_score = intval($post_ratings_data['ratings_score'][0]);
    $post_ratings_average = floatval($post_ratings_data['ratings_average'][0]);
}

Any Solution ?

share|improve this question
add comment

1 Answer

when ever you expect something to be an array, it's good practice to check to see if it is first before proceeding. so the new code might read like this:

if(is_null($post_ratings_data)) {
    $post_ratings_data = get_post_custom($post_id);
    if ( is_array( $post_ratings_data['ratings_users'] ) ) {
        $post_ratings_users = intval($post_ratings_data['ratings_users'][0]);
        $post_ratings_score = intval($post_ratings_data['ratings_score'][0]);
        $post_ratings_average = floatval($post_ratings_data['ratings_average'][0]);
    }
}
share|improve this answer
    
its still giving the same error, any other suggestion ? –  harry Jan 12 '12 at 6:02
    
notices are not really a problem, you should probably look for fatal errors, sometimes they are hidden in the output due to css issues. Other than that, there are too many variables to help you with. –  Deryk Wenaus Jan 12 '12 at 6:22
    
its works fine ... all i wanted is to make it clear, without notices –  harry Jan 12 '12 at 6:56
    
edited, as always I should have read the error message more slowly. :) the system is expecting $post_ratings_data['ratings_users'] to be an array, but for whatever reason it's not. –  Deryk Wenaus Jan 12 '12 at 7:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.