Title: Using URL parameters
Last modified: August 21, 2016

---

# Using URL parameters

 *  [NeoBean](https://wordpress.org/support/users/neobean/)
 * (@neobean)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/using-url-parameters-1/)
 * Hey TC!
 * I’ve been trying to figure out how someone could make a hyperlink that would 
   have a few desired taxonomy checkboxes checked using URL parameters, with the
   results filtered accordingly, either as the page loads or after a short second.
 * Something like- [http://mysite.com/?category=music&artist=Sting](http://mysite.com/?category=music&artist=Sting)
 * I’ve tried several things but nothing has worked. Do you know how this could 
   be implemented? Any pointers would be great :]
 * Thanks for all your help!
 * [https://wordpress.org/plugins/ultimate-wp-query-search-filter/](https://wordpress.org/plugins/ultimate-wp-query-search-filter/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [TC.K](https://wordpress.org/support/users/wp_dummy/)
 * (@wp_dummy)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795804)
 * Why don’t use a custom template to display the posts? With custom template you
   can defined the custom query load first when the page load.
 *  Thread Starter [NeoBean](https://wordpress.org/support/users/neobean/)
 * (@neobean)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795808)
 * I hadn’t thought of custom templates- what plugin hook could I use to do that?
   An example would be awesome, but I know you have limited time :]
 * The other thing though is that setting up a custom template for each could be
   unnecessary duplicate work- if a URL parameter were used, we could re-use the
   same page/code and create things on the fly. So instead of, say 20 pages, I could
   just have 20 URLs instead.
 * Thanks so much!
 *  Plugin Author [TC.K](https://wordpress.org/support/users/wp_dummy/)
 * (@wp_dummy)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795832)
 * Actually custom template is the wp default feature, not in my plugin.
    You can
   check on this [documentation](http://codex.wordpress.org/Page_Templates) of how
   to create a custom template with custom query.
 *  Thread Starter [NeoBean](https://wordpress.org/support/users/neobean/)
 * (@neobean)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795835)
 * Ah, I see what you’re saying; maybe I can make what I’m trying to do a bit more
   clear-
 * Say I have a search form that has 3 taxonomies- Category, Genre, and Artist. 
   The search form has checkboxes for the categories, genres, and artists, which
   is great. What I want to do, is instead of making the user click on the “Rock
   and Roll” checkbox under the “Genre” taxonomy, is I give them a URL that comes
   with “Rock and Roll” already checked and the R&R results filtered. Like so- [http://example.com/?filter=rockandroll](http://example.com/?filter=rockandroll)
 * So far I already have code to grab which URL parameter is used, so I just want
   to pass that in and POST to update the page after it loads (or ideally before).
   Can you tell me what event/function on the page sends the POST to update the 
   results for checkboxes? I’ve looked in uwpqsfscript.js and saw the jQuery.ajax
   call but am not sure exactly how this is used to trigger the update. Thanks!
 *  Plugin Author [TC.K](https://wordpress.org/support/users/wp_dummy/)
 * (@wp_dummy)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795850)
 * I am not quite sure what you meant, but if you want to submit the query on page
   load you can use:
    `$('#uwpqsffrom_{form_id} .usearchbtn').click();`
 *  Thread Starter [NeoBean](https://wordpress.org/support/users/neobean/)
 * (@neobean)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795855)
 * I got this to work using a slightly different call. I copied the process_data
   function into a header script that then calls
 * process_data($(‘#tchkb-0-‘+filterBy).click());
 * where filterBy is the parameter passed in from the URL; you’ll also notice I 
   had to edit the front-class.php file to append -‘.$value.’ to each ID for my 
   checkboxes so they could be programmatically selected.
 * Works great!
 *  [slickorange](https://wordpress.org/support/users/slickorange/)
 * (@slickorange)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795973)
 * Hi NeoBean! I am looking to do exactly the same thing, is it possible to share
   your code?
 *  Thread Starter [NeoBean](https://wordpress.org/support/users/neobean/)
 * (@neobean)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795976)
 * Hey slickorange, sorry for the delay! This is what I did, hope it still helps.
 * 1) Paste this into a new .js file-
 *     ```
       <!-- Load page with some boxes pre-checked -->
       var urlParams;
       (window.onpopstate = function () {
           var match,
               pl     = /\+/g,  // Regex for replacing addition symbol with a space
               search = /([^&=]+)=?([^&]*)/g,
               decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
               query  = window.location.search.substring(1);
   
           urlParams = {};
           while (match = search.exec(query))
              urlParams[decode(match[1])] = decode(match[2]);
       })();
   
       var filterBy = urlParams["filter"];
   
       jQuery(document).ready(function ($) {
   
       	window.process_data = function ($obj) {
   
       			var ajxdiv = $obj.closest("form").find("#uajaxdiv").val();
       			var res = {loader:$('<div />',{'class':'umloading'}),container : $(''+ajxdiv+'')};
   
       			var getdata = $obj.closest("form").serialize();
       			var pagenum = '1';
   
       			jQuery.ajax({
       				 type: 'POST',
       				 url: ajax.url,
       				 data: ({action : 'uwpqsf_ajax',getdata:getdata, pagenum:pagenum }),
       				 beforeSend:function() {$(''+ajxdiv+'').empty();res.container.append(res.loader);},
       				 success: function(html) {
       					res.container.find(res.loader).remove();
       				  $(''+ajxdiv+'').html(html);
   
       				 }
       			});
   
       	}	
   
       	process_data($('#tchkb-0-'+filterBy).click());
       	process_data($('#tchkb-1-'+filterBy).click());
       	process_data($('#tchkb-2-'+filterBy).click());
       	process_data($('#tchkb-3-'+filterBy).click());
   
       });
       ```
   
 * Add or remove process_data calls according to how many you need- one for each
   section.
 * 2) Link that file in your header. WP offers many ways of doing this- plugin, 
   functions.php, or direct if you’re positive that’s what you want to do.
 * 3) Edit uwpqsf-front-class.php to include the id value, so around line 37 in 
   mine-
 * `$html .= '<label><input type="checkbox" id="tchkb-'.$c.'-'.$value.'" name="taxo['.
   $c.'][term][]" value="'.$value.'" >'.$term->name.'</label>';`
 * 4) Then create links with ?filter=VALUE at the end to filter by the value you
   want to filter by. Also note the value should be formatted as a slug, not with
   spaces or stuff.
 * I think that should be everything. It’s been a while since I implemented this
   so things are a bit fuzzy. Good luck!
 *  [slickorange](https://wordpress.org/support/users/slickorange/)
 * (@slickorange)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795977)
 * Thanks NeoBean, I managed (your initial post did steer me in the right direction)
   but I am sure your code will help somebody else.. My requirements were a bit 
   more basic. The code I used is this:
 *     ```
       jQuery(document).ready(function($) {
                $('[id^=tdp-] option[value="<?php echo $select_value?>"]').attr("selected", "selected");
   
                function loadAjax(){
                   var obj = $("[id^=uwpqsffrom_]");//remember to replace the form id
   
                   process_data(obj);
                    return false;
                   }
                   window.onload = loadAjax;
   
           });
       ```
   
 * The nice thing is that even if I add another taxonomy dropdown filter the code
   will need no adjustment. You can see it in use here: [http://www.movingintoaction.co.za/category/directory](http://www.movingintoaction.co.za/category/directory)

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Using URL parameters’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/ultimate-wp-query-search-filter_fcfcfc.
   svg)
 * [Ultimate WP Query Search Filter](https://wordpress.org/plugins/ultimate-wp-query-search-filter/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ultimate-wp-query-search-filter/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/)
 * [Active Topics](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ultimate-wp-query-search-filter/reviews/)

 * 9 replies
 * 3 participants
 * Last reply from: [slickorange](https://wordpress.org/support/users/slickorange/)
 * Last activity: [11 years, 9 months ago](https://wordpress.org/support/topic/using-url-parameters-1/#post-4795977)
 * Status: not resolved