Listable – redirect category to archive page

mgibbs189

{{gist file=”functions.php” lang=”php”}}
<?php

// Add to your (child) theme’s functions
function fwp_homepage_redirect() {
?>
<script>
(function($) {
$(function() {
// replace the submit button’s “onclick” handler
$(‘.search_jobs–frontpage-facetwp .search-submit’).attr(‘onclick’, ‘custom_redirect()’);
});
})(jQuery);

function custom_redirect() {
FWP.parse_facets();
FWP.set_hash();
var query_string = FWP.build_query_string();
if (” != query_string) {
query_string = ‘?’ + query_string;
}
var pagename = ‘/postes/’;
if (FWP.facets.categories.length > 0) {
pagename = ‘/category-listing/’ + FWP.facets.categories[0];
}

window.location.href = pagename + query_string;
}
</script>
<?php
}
add_action( ‘wp_head’, ‘fwp_homepage_redirect’, 100 );
{{/gist}}