Got a little problem hopefully I can get some help. I noticed that after I added a "sort post by" code to my index my navigation broke. If you click on page two you still get the contents of page one. I did a little digging and found the problem, only thing is I not sure how to fix it. Here is the loop from my index page. Now I need to exclude a selected category from the main loop, that's the first part. The second part is if I add $orderby to the query_posts string (second to the last line) then the navigation breaks. If I remove it then it works. I tried to have to query_posts strings, but that didn't work out. Anyway to make this work or do I have to give up one for the other?

    $featcat = get_option($shortname.'_featured_category');      
    $category_id = get_cat_ID($featcat);
$paged = (get_query_var('paged'))?get_query_var('paged'):1;
$q = array();
$q['category__not_in'] = array($category_id);
$q['paged'] = $paged;
if (have_posts()) : while (have_posts()) : the_post(); ?>

1 Answer 1


The problem is $q is and array and $orderby is a string. So $q.$orderby doesn't make sense. (Untested) but remove $orderby and try


(The orderby key can have any value given in this list in the Codex.). Also, it would be neater to use this syntax:

$q = array(
    'category__not_in'=> array($category_id),
    'paged' => $paged,


If you you are trying to make this compatible with the WP-PostRatings plug-in, instead of using the query string&r_sortby=highest_rated&r_orderby=desc, you can put it in array format:

$q = array(
    'category__not_in'=> array($category_id),
    'paged' => $paged,
    'meta_key' => 'highest_rated',
    'orderby'=>'meta value',

*Note, I've not tested this nor checked the plug-in', but 'highest_rated' should be the meta key of the post's rating. See the Codex for more details.*

  • Thanks for the cleaned up code, but I need to have two query_post in the loop. One for the $q and then one for $orderby. I have a function that the post get sorted after a user selects to order them by "top rated", "Most viewed" and "Latest". That was the reason I was using $q.$orderby.
    – Kurt Bunch
    Commented Mar 13, 2012 at 22:28
  • Then whatever that $orderby is you pass it to $q['orderby']. Commented Mar 13, 2012 at 22:42
  • Still no luck. It needs to have that query_post($orderby) to work.
    – Kurt Bunch
    Commented Mar 14, 2012 at 4:28
  • I can't see why. Can you give an example of a value for $orderby? Commented Mar 14, 2012 at 9:22
  • This is part of the code from the order function. case 'rated' : $orderby = '&r_sortby=highest_rated&r_orderby=desc';
    – Kurt Bunch
    Commented Mar 15, 2012 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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