WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 1 down vote accepted

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


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'.


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

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
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
Updated my answer to include the IF statement – Stephen Harris Oct 24 '11 at 19:48

Your Answer


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.