Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have one question. I need to query posts from category based on the filter most favorited ( http://pastie.org/2751114 ) which is placed in custom_sort.php to my index.php page

This is how the posts from categories are called ( http://pastie.org/2751131 ) in index.php.

Is there any way to get the posts from category based on the most favorited filter?

Thank You so very much in advance :D

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

query_posts accepts custom query variable as arguments. So assuming that adding

?sort_by=most_favourites

to an url alters the sort order to sort by the most favourites (i.e. you've set sort_by as a recognised WordPress query variable, and setting it sorts the returned posts accordingly) then, try:

$args = array(
    'cat' => $cat_lists[$i],
    'showposts' => intval(get_theme_option_by('bn_list_per_item', 6 )),
    'sort_by' => 'most_favourites',
    'post_type' => 'post');

That should return the set number of posts from the category selected, in order of 'most_favourites'.

Update:

To alter the the value of sort_by for category with ID 30 (say), put the following, after $arg and before query_posts:

 if($cat_lists[$i]==30){
    $args['sort_by']='most_commented';
}
share|improve this answer
    
HAHAH it did the trick, but it's not most_favourites, instead is: most_favorites . One letter to much. Thank You so very much. You are an inspiration and a big help. I really appreciate it! –  jimilesku Oct 24 '11 at 17:16
    
is it possible to give the option for one of 3 categories to show different sort? I would like to create a most_commented filter on 1 category. Is it possible? –  jimilesku Oct 24 '11 at 17:19
1  
That's because I was writing in English :P. Glad to help :D. As for using a different sorting method, you can just use an if statement to change the $args array when $cat_lists[$i] == some ID. You just need to alter the sort_by line to: 'sort_by'=> 'most_commented' –  Stephen Harris Oct 24 '11 at 17:36
    
I'm a bit of a noob so could You tell me if the IF statement comes after the query or inside the $args? could you give me an example for category number 30 in pastie maybe so I can understand and use the code? –  jimilesku Oct 24 '11 at 18:04
1  
Updated my answer to include the IF statement –  Stephen Harris Oct 24 '11 at 19:48
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.