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.

What i'm trying to do here is to modify the existing wp-postratings plugin. The function to display the ratings is:

<?php if(function_exists('the_ratings')) { the_ratings(); } ?>

However, the above code displays the ratings on every post. What would be the conditional statement to add such that if a post has a custom field with name/value as ratings/yes

This way, based on the conditional statement, the ratings would be displayed only on posts where the custom field has the ratings/yes added.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted
<?php
// get the value of our custom field
$meta_value = get_post_meta($post->ID, 'ratings', true);
// if it's not empty and the_ratings function exists:
if( !empty($meta_value) && function_exists('the_ratings') ){
    the_ratings();
}
share|improve this answer
    
Thanks.. but this code doesn't seem to do anything. The ratings have disappeared from all the posts now. I've set the custom field/value to ratings/yes. –  Sledge81 Jul 18 '11 at 14:04
    
sorry, updated it to change $post_id to $post->ID, which will actually exist if you're using this in the loop. –  Milo Jul 18 '11 at 14:16
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.