Cant Re-sort Post Loop Order with Highest Post Ratings from User Form Submission
-
I want to allow the site user to re-sort my post loop order based on either most recent posts or highest rated posts (as defined by WP-PostRatings) using a drop down list form.
Here is my example but only the “date” sorting works. I can’t get it to sort for “highest_rated” from this form:
<?php $sort= $_GET['sort']; if($sort == "date") { $order= "orderby=date"; } if($sort == "highest_rated") { $order= "orderby=meta_value_num"; } ?>
<form action="" method="get"> <select name="sort" id="sorting"> <option value="date" <?php if ($sort == "date"){ echo 'selected="selected"'; } ?> >Most Recent Posts</option> <option value="highest_rated" <?php if ($sort == "highest_rated"){ echo 'selected="selected"'; } ?> >Highest Rated Posts</option> </select> <input type="submit" value="Submit" /></form>
After testing it, it doesn’t change the order of the loop at all, but the url changes to mysite.com/?sort=highest_rated.
Is it possible to re-sort based on highest post ratings through a user submit drop down list form on the front end?
I did find the following FAQ explaining High/Low sorting, but I can’t seem to pull the right information out of this for my usage in the form, and I’ve tried many combinations:
“To Sort Highest/Lowest Rated Posts
You can use: <?php query_posts( array( ‘meta_key’ => ‘ratings_average’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ ) ); ?>
Or pass in the variables to the URL: https://yoursite.com/?r_sortby=highest_rated&r_orderby=desc
You can replace desc with asc if you want the lowest rated posts.”I would appreciate any help on this, I’m not a PHP expert. I can’t seem to find anything like this for a form that works for this specific plugin’s ratings, but it seems like they would plug right into a form, just feel like I’m not using the correct call tags.
Thanks in advance.
- The topic ‘Cant Re-sort Post Loop Order with Highest Post Ratings from User Form Submission’ is closed to new replies.