• averixus

    (@averixus)


    I have a custom post type, with filters for two custom taxonomies on the main post type archive (using the Filter Everything plugin). I want to add an option to change the sort order of the posts.

    I created buttons which add the chosen sort to the query. This works fine when it’s applied to the full archive (with no other queries). If I then filter using FE, the chosen sort order is retained on the filtered posts.

    But if I filter using FE *first*, and then click the sort order button, the filter queries are lost. I can’t figure out why this happens, or how to re-add them back to the query that’s sent when clicking the sort order button. I’ve tried setting the form action to the current full url ($_SERVER[‘REQUEST_URI’]), but the custom taxonomy queries are still lost.

    Why do the custom taxonomy queries disappear when sending a new query? How do I add them back to the new query that’s sent using a form submission?

    The page I need help with: [log in to see the link]

Viewing 1 replies (of 1 total)
  • Thread Starter averixus

    (@averixus)

    I’ve managed to achieve it by manually parsing the existing queries and turning them back into hidden input fields:

    $current_taxes = $wp_query->query_vars['tax_query'];
    $hidden_queries = '';
    	foreach ($current_taxes as $tax) {
    		$tax_name = str_replace('_', '-', $tax['taxonomy']);
    		$tax_terms = implode(';', $tax['terms']);
    		$new_query = '<input type="hidden" name="' . $tax_name . '" value="' . $tax_terms . '">';
    		$hidden_queries .= $new_query;
    }

    Then adding those input fields into the sort button form. If there’s a more elegant way to do this I’d love to hear it.

Viewing 1 replies (of 1 total)
  • The topic ‘How to add all current filter query parameters back to a new query?’ is closed to new replies.