• Resolved lukecooperdesign

    (@lukecooperdesign)


    Is there a way to check if a post has been rated yet? I want to display the result only if the post has been rated. If the post hasn’t been rated yet, then show form (instead of “No ratings yet” text). Something like this:

    if ( *if_post_has_been_rated* ) {
    	echo do_shortcode('[mr_rating_result]');
    } else {
    	echo do_shortcode('[mr_rating_form]');
    }

    Is this possible?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter lukecooperdesign

    (@lukecooperdesign)

    Nevermind, I got it. 🙂

    if ( get_post_meta( get_the_ID(), Multi_Rating::RATING_RESULTS_POST_META_KEY, true )['count'] > 0 ) {
    	echo do_shortcode('[mr_rating_result]');
    } else {
    	echo do_shortcode('[mr_rating_form]');
    }
    Plugin Author dpowney

    (@dpowney)

    Yes that will work. Another way is to do this.

    if ( class_exists( 'Multi_Rating_API' ) ) {
    	
    	$post_id = get_the_ID();
    	$rating_result = Multi_Rating_API::get_rating_result( $post_id );
    	
    	if ( $rating_result['count'] > 0 ) {
    		echo do_shortcode('[mr_rating_result post_id="' . $post_id . '"]');
    	} else {
    		echo do_shortcode('[mr_rating_form post_id="' . $post_id . '"]');
    	}
    }

    I have not tested this code snippet but you get the idea.

    Daniel

    • This reply was modified 9 years, 7 months ago by dpowney.
    Thread Starter lukecooperdesign

    (@lukecooperdesign)

    Thanks dpowney! I went with that solution in case the plugin gets uninstalled.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Check if a post has been rated.’ is closed to new replies.