I've got custom taxonomy archive pages with a drop down list that allows users to re-order/sort the posts. It basically waits for the user to select from the drop down then uses array_merge( $wp_query->query..... to create a new query and re-sort the posts. This works fine. I also use wp-pagination to display numbered pagination. This also works fine.

The problem is, when a user re-sorts the list, and then clicks on the pagination to go to page 2 the new sort is lost and reverts back to the original. I can't work this out. Any ideas?

1 Answer 1


I had the same problem. I was using a form to sort the data, and a pagination using paginate_links. My solution was to use $_SESSIONS to store the $_POST data from the sort (instead of just parsing the $_POST data), and set the form action to get_permalink(). Make sure to unset your session if you are not using pagination or if you are not $_POST ing the sort form.

function submitform(val) {
    document.getElementById('sort-option').value = val;

<form id="form-sort" action="<?php echo get_permalink(); ?>" method="post">
        <li>Sort By:</li>
        <li><a href="#!" onclick="javascript: submitform('newest');">Newest rating</a>
        <li><a href="#!" onclick="javascript: submitform('highest');">Highest rating</a>
        <li><a href="#!" onclick="javascript: submitform('lowest');">Lowest rating</a>
    <input type='hidden' id='sort-option' name='sort-option' value=''>


if($wp_query->get('page') == 0 && empty($_POST) && !empty($_SESSION)) session_unset();

if(!empty($_POST) || !empty($_SESSION)) {

    switch($_POST['sort-option']) {
        case 'newest':
            $_SESSION["sort"] = SORT_DESC;
            $_SESSION["sort_by"] = 'review_date';
        case 'highest':
            $_SESSION["sort"] = SORT_DESC;
            $_SESSION["sort_by"] = 'rating';
        case 'lowest':
            $_SESSION["sort"] = SORT_ASC;
            $_SESSION["sort_by"] = 'rating';

    foreach($reviews as $k => $v) {
        $column_id[$k] = $v[$_SESSION["sort_by"]];

    array_multisort($column_id, $_SESSION["sort"], SORT_NUMERIC, $reviews);


If you show some code, I might be able to help you more.

  • Thanks for helping. I ended up paying someone to fix it for me.
    – Luke Seall
    Commented Aug 1, 2014 at 11:21

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.