WordPress.org

Forums

kk Star Ratings
[resolved] Setting default rating for KK stars (13 posts)

  1. zerackam
    Member
    Posted 1 year ago #

    Hi im wondering if there is a way for me to set the KK star ratings for all of the pages to a default level automatically which then gets changed as people vote for different values. Ie. when a post is created and the stars are automatically placed at the bottom of the post can they come up at a present number of stars by default even before anyone votes on them.

    Thanks

    http://wordpress.org/extend/plugins/kk-star-ratings/

  2. Kamal Khan
    Member
    Plugin Author

    Posted 1 year ago #

    add_action('save_post', 'auto_rate_post');
    
    function auto_rate_post($post_id)
    {
    	if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
    	{
    		return $post_id;
    	}
    
    	if(!isset($_POST['post_type']) || !current_user_can('edit_post', $post_id))
    	{
    		return $post_id;
    	}
    
    	$stars = 4;
    
    	$total_stars = is_numeric(get_option('kksr_stars')) ? get_option('kksr_stars') : 5;
    
    	if(!get_post_meta($post_id, '_kksr_ratings', true))
    	{
    		$ratings = $stars / ($total_stars/5);
    		$avg = $ratings ? number_format((float)$ratings, 2, '.', '') : 0;
    
    		update_post_meta($post_id, '_kksr_ratings', $ratings);
    		update_post_meta($post_id, '_kksr_casts', 1);
    		update_post_meta($post_id, '_kksr_avg', $avg);
    	}
    
    	return $post_id;
    }

    Change the $stars = 4; to the amount of stars you want.

  3. zerackam
    Member
    Posted 1 year ago #

    I tried placing it in my theme CSS but it did not do anything. Is there another place i should put this code?

    Thanks.

  4. Kamal Khan
    Member
    Plugin Author

    Posted 1 year ago #

    functions.php located in your theme folder :-P

  5. zerackam
    Member
    Posted 1 year ago #

    LOL yeah im definately new to this but thanks Kamal you are always awesome. I placed it into the functions.php for the theme i'm using on fibroid.co but its still a no go.

  6. Kamal Khan
    Member
    Plugin Author

    Posted 1 year ago #

    did you try creating a new post?

    It will work for posts that do no have any ratings whenever you click the publish/update button

  7. zerackam
    Member
    Posted 1 year ago #

    Umm i just wanted to reiterate that you are a PIMP. Thank you again. If there is ever anything a mere mortal such as myself can do for you just name it.

  8. Kamal Khan
    Member
    Plugin Author

    Posted 1 year ago #

    ooh that was harsh

  9. zerackam
    Member
    Posted 1 year ago #

    LOL i didnt even realize what what i said was rude sorry my farsi is not that good. but I meant that only in the best of ways. You are the man. Thanks.

  10. Kamal Khan
    Member
    Plugin Author

    Posted 1 year ago #

    fine

  11. huyforex
    Member
    Posted 1 year ago #

    How to setting default rating for old post.

    I have about 3000 post. I want to have setting default about 1 vote for 3000 post.

    Please help me

  12. mbfis
    Member
    Posted 1 year ago #

    Up!
    How to set a default rating for old post please?
    Thanks,

  13. tecvoid
    Member
    Posted 1 year ago #

    or an autovoter, something! tell me how to vote up all my stuff

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • kk Star Ratings
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic