I am using these code to sort most Commented, Most viewed Posts
<?php $params = $_GET;
unset($params['orderby']);
unset($params['order']);
unset($params['v_orderby']);
unset($params['v_sortby']);
$url = $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
$url = strtok($url, '?');
$url =$url.'?'.http_build_query($params);
?>
<ul id="sort">
<li <?php if($active == "date"): ?> class="active"<? endif ?>><a href="http://<?php echo
$url ?>">Most Rated</a></li>
<li <?php if($active == "comment"): ?> class="active"<? endif ?>><a href="http://<?php echo $url ?>&orderby=comment_count&order=desc">Most commented </a></li>
<li <?php if($active == "views"): ?> class="active"<? endif ?>><a href="http://<?php echo $url ?>&v_sortby=views&v_orderby=desc">Most viewed </a></li>
</ul>
Now I want to sort Custom Field "Rating" as Most Rated here is the code of custom field.
<?php
//grab the rating value
$rating = get_post_meta($post->ID, 'rating', true);
//prints star image
for ($i=1; $i<=$rating; $i++){
echo '<img src="/images/star.png"/>';
}
//prints unstar image
for ($i=$rating; $i<10; $i++){
echo '<img src="/images/unstar.png"/>';
}
?>
For this I used this code, but it's not working.
<a href="http://<?php echo $url ?>&orderby=rating&order=desc">Most Rated</a>