WordPress.org

Support

Support » Plugins and Hacks » kk Star Ratings » [Resolved] [Plugin: kk Star Ratings] Ordering post by kk rating

[Resolved] [Plugin: kk Star Ratings] Ordering post by kk rating

  • First of all Thank you very much for this great plugin.

    I’m trying to reorder posts by kk star rating, not by date.
    I mean each time post is rated, post goes up or down depending on rating.
    so I added custom meta-key to my posts template, and now posts are ordered by meta_key values . like this

    <?php query_posts('meta_key=asd&orderby=meta_value&order=ASC'); ?>

    now I need to pass kk rating to my custom meta_key(“asd” in my case) as value for each posts… and I don’t know how to do it.

    here is my site http://horror-movies.co/

    Thank you so much for your help.

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

Viewing 15 replies - 1 through 15 (of 27 total)
  • I’m guessing i have to use

    <?php update_post_meta($post_id, $meta_key, $meta_value, $prev_value); ?>
    in kk-ratings.php file but I don’t know where and how exactly…

    Thanks again for your help…

    Plugin Author Kamal Khan

    @bhittani

    Hi

    Can you explain this: “now I need to pass kk rating to my custom meta_key(“asd” in my case) as value for each posts… and I don’t know how to do it.”

    I didn’t understand this point. Maybe if you brief me about the actual meta_key(instead of asd) and for what purpose you are using it, I may understand better.

    Thanks

    Hello Kamal,

    Thanks for superfast reply 🙂 and sorry for my English.

    Basically what I want to do is to order posts by post rating.
    Usually they are ordered by date.

    Actual meta_key in my case is “asd”…I should give it more descriptive name , like “rating” or something but that’s not a point.

    What I want to do is to assign kk-star-rating value for each post, to my meta_key as value., so when user rates movie with say 5 star movie (post) goes up, if user rates with 1 star post it goes down…

    hopefully I explained more clearly this time 🙂

    Thanks

    Plugin Author Kamal Khan

    @bhittani

    What you mean is that you just want the post to be ordered by rating (Descending order)? So top rated is at top and lesser rated come below?

    Exactly. That’s what I want.

    Plugin Author Kamal Khan

    @bhittani

    You may want to use this code instead of your current loop.

    if(function_exists(‘kk_star_ratings_get’)) :
        $top_rated_posts = array();
        $top_rated_posts = kk_star_ratings_get(10);
        if(count($top_rated_posts)) :
        wp_reset_query();
        foreach($top_rated_posts as $post)
       {
            $mypost = get_post($post->ID);
            $title = $mypost->post_title;
            $excerpt = $mypost->post_excerpt;
            $permalink = get_permalink($mypost->ID);
            echo $title;
            echo $excerpt;
            echo $permalink;
            wp_reset_query();
        }
        endif;
    endif;

    Hope that works 🙂

    Plugin Author Kamal Khan

    @bhittani

    Also, you may want to use this post meta value which is being stored by the plugin for each post.

    _kk_ratings_avg

    This is the post meta containing the average ratings for each post.

    Hope that helps

    Plugin Author Kamal Khan

    @bhittani

    I guess this will work for you:

    <?php
     query_posts('meta_key=_kk_ratings_avg&orderby=meta_value&order=DESC');
    ?>

    Were exactly should I put that code…here is my file

    <?php query_posts(‘meta_key=asd&orderby=meta_value&order=ASC’); ?>

    <?php
    
    /**
    
     * This file creates a blog-style layout of posts, useful if you are creating a generic blog.
    
     * This file is not to be loaded directly, but is instead loaded from different templates.
    
     *
    
     * @package Suffusion
    
     * @subpackage Templates
    
     */
    
    global $suffusion, $query_string, $wp_query, $suffusion_current_post_index, $suffusion_full_post_count_for_view, $suffusion_blog_layout, $suffusion_duplicate_posts;
    
    $suffusion_blog_layout = true;
    
    if (!isset($suffusion_duplicate_posts)) $suffusion_duplicate_posts = array();
    
    global $post;
    
    if (have_posts()) {
    
    	$suffusion_current_post_index = 0;
    
    	$suffusion_full_post_count_for_view = suffusion_get_full_content_count();
    
    	while (have_posts()) {
    
    		the_post();
    
    		$original_post = $post;
    
    		if (in_array($post->ID, $suffusion_duplicate_posts)) {
    
    			continue;
    
    		}
    
    		$suffusion_current_post_index++;
    
    		global $suf_category_excerpt, $suf_tag_excerpt, $suf_archive_excerpt, $suf_index_excerpt, $suf_search_excerpt, $suf_author_excerpt, $suf_show_excerpt_thumbnail, $suffusion_current_post_index, $suffusion_full_post_count_for_view, $suf_pop_excerpt, $page_of_posts;
    
    		if (($suffusion_current_post_index > $suffusion_full_post_count_for_view) && ((is_category() && $suf_category_excerpt == "excerpt") ||
    
    			(is_tag() && $suf_tag_excerpt == "excerpt") ||
    
    			(is_search() && $suf_search_excerpt == "excerpt") ||
    
    			(is_author() && $suf_author_excerpt == "excerpt") ||
    
    			((is_date() || is_year() || is_month() || is_day() || is_time())&& $suf_archive_excerpt == "excerpt") ||
    
    			(isset($page_of_posts) && $page_of_posts && $suf_pop_excerpt == "excerpt") ||
    
    			(!(is_singular() || is_category() || is_tag() || is_search() || is_author() || is_date() || is_year() || is_month() || is_day() || is_time()) && $suf_index_excerpt == "excerpt"))) {
    
    			$show_image = $suf_show_excerpt_thumbnail == "show" ? true : false;
    
    			$classes = array('excerpt');
    
    		}
    
    		else {
    
    			$classes = array('full-content');
    
    		}
    
    ?>
    
    	<div <?php post_class($classes);?> id="post-<?php the_ID(); ?>">
    
    <?php
    
    		suffusion_after_begin_post();
    
    ?>
    
    	<div class="entry-container fix">
    
    		<div class="entry entry-content fix">
    
    <?php
    
    		suffusion_content();
    
    ?>
    
    		</div><!--entry -->
    
    <?php
    
    		// Due to the inclusion of Ad Hoc Widgets the global variable $post might have got changed. We will reset it to the original value.
    
    		$post = $original_post;
    
    		suffusion_after_content();
    
    ?>
    
    	</div><!-- .entry-container -->
    
    <?php
    
    		suffusion_before_end_post();
    
    ?>
    
    	</div><!--post -->
    
    <?php
    
    	}
    
    	suffusion_before_end_content();
    
    }
    
    else {
    
    	get_template_part('layouts/template-missing');
    
    }
    
    ?>

    OK I will try and let you know. Thanks so much 🙂

    Plugin Author Kamal Khan

    @bhittani

    Most welcome.

    Just use this for querying the post

    query_posts('meta_key=_kk_ratings_avg&orderby=meta_value&order=DESC');

    WOOHOOO ITS WORKING !!! THANK YOU! THANK YOU !THANK YOU!

    Plugin Author Kamal Khan

    @bhittani

    I am glad it worked. Have fun 🙂

    This is exactly what I was looking for. Now the only thing is, if a post has not been rated yet, it doesn’t show up.

    That’s working for me aswell, thanks!

    One only question is that posts without a rating won’t appear anymore. Is there a way to solve this issue?

Viewing 15 replies - 1 through 15 (of 27 total)
  • The topic ‘[Resolved] [Plugin: kk Star Ratings] Ordering post by kk rating’ is closed to new replies.
Skip to toolbar