WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 2 down vote accepted
// 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') ){
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

Your Answer


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.