1

I am using a drop-down to sort posts by title, meta_value, etc. However, the sorting feature only works on the first page. The second page displays the default order rather than continuing the order from page 1. I am using wp-pagenavi for pagination. Any ideas what would be causing this error?

Here's a link to the code:

http://pastebin.com/AwSmMPtM

Thanks so much.

2 Answers 2

2

You're initially submitting a POST request via a form with the sort parameters. When you click links to additional pages, you're just sending a GET request for the next page without those original POST vars, so they don't carry over to the additional pages and aren't picked up by your if(isset($_REQUEST['sort'])). Probably the simpler way to handle it is to pass the sort parameter as a query string appended to the URL, then check for that query string and append it to the URLs of the additional pages.

2
  • Upvoted... didn't notice the form action.
    – s_ha_dum
    Nov 18, 2012 at 21:14
  • Thanks for your feedback. I understand what you're saying. Unfortunately, I don't know enough PHP to know what this looks like in code. Would you be able to provide a coding example of what you're suggesting? Thank you very much.
    – John Hall
    Nov 18, 2012 at 21:40
1

You are setting $paged after the if conditionals that use it.

// more uses of $paged that way ^^^^
else
        $order = array(
        'cat' => 30,
        'orderby' => 'title',
        'order' => 'ASC',
        'paged' => $paged
);

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

Put that $paged = line before those conditionals and I bet it makes a difference.

Your Answer

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

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