(function( $ ) { $( document ).ready( function() { $( document ).on( 'submit', '.adv-search-form, .search-form', function( e ) { const input = $( this ).find( 'input[name=s]' ); // We've found something that isn't likely a WordPress search if ( input.length === 0 ) { return; } let keywords = $.parseHTML( input.val() ); const urlParams = new URLSearchParams( window.location.search ); let args = { 'type': $(this).find('select[id=type]').val() || '0', 'channel': $(this).find('select[id=channel]').val() || '0', 'sort_results': $( this ).find( '#sort_results_rel' ).prop( "checked" ) ? 'rel' : 'date_desc', }; const fromInput = $( this ).find( 'input[name=from]' ); if ( urlParams.get( 'from' ) !== '' || fromInput.val() !== '' ) { args.from = $( this ).find( 'input[name=from]' ).val(); } keywords = $( keywords ).text(); // Assign rather than replace so history still works. window.location.assign( '/search/' + keywords + (keywords ? '/?' : '?') + $.param( args ) ); e.preventDefault(); } ); } ); })( window.jQuery || window.Zepto );