Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter NeoBean

    (@neobean)

    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!

    Thread Starter NeoBean

    (@neobean)

    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!

    Thread Starter NeoBean

    (@neobean)

    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- https://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!

    Thread Starter NeoBean

    (@neobean)

    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!

    Thread Starter NeoBean

    (@neobean)

    Awesome, thank you! I really appreciate it :]

    Thread Starter NeoBean

    (@neobean)

    Hmm, for some reason that doesn’t work at all- all categories are displayed, not just the ones I tried to include.

    I don’t have any exclusions set, not that it would matter since they’d be cleared anyway.

    You know, we could take this in another direction…when I use:

    add_filter(‘uwpqsf_taxonomy_arg’,’include_wpsqf_term’,”,2);
    function include_wpsqf_term($args,$formid){
    $args[‘exclude’]=”;//clear any exclude term id if there any
    $args[‘include’] = array(156,157,160,161,159,158);//include all the term id you want to add.
    return $args;
    }

    The inclusion works, but any other taxonomies I add just render as “checkbox checkbox checkbox”. If we could solve the multiple taxonomy issue, I would probably be OK just having one form.

    Thread Starter NeoBean

    (@neobean)

    Sorry for the delay, here it is-

    add_filter(‘uwpqsf_taxonomy_arg’,’include_wpsqf_term’,”,2);
    function include_wpsqf_term($args,$formid){
    $args[‘exclude’]=”;//clear any exclude term id if there any
    $args[‘include’] = array(156,157,160,161,159,158);//include all the term id you want to add.
    $formid = 779;
    return $args;
    }

    However, even with only one of these blocks (i.e., removing the formid altogether and only using one form) it messes up the other taxonomies I add. So if I try to “include” categories but also allow for custom taxonomies or tags, they only show up as “checkbox”

    Thanks for your help!

    Thread Starter NeoBean

    (@neobean)

    I used it in the function, right before

    return args;

    as well as tried passing it in directly in the parameter, like

    function include_wpsqf_term($args,800){

    And neither seemed to work.

    Thread Starter NeoBean

    (@neobean)

    Thank you so much! That works- I just had to remove both of the ‘ apostrophes from the include array list. So for others wondering, it should be:

    $args['include'] = array(1,2,3,4,5);

    Last question- to use this with multiple forms, I tried using the $formid parameter but without luck. I tried adding:

    $formid = [your_id_here];

    on the line before the return statement, and duplicating the function and filters then using a different $formid and renaming the function, but no luck (it just uses the second function I create, probably because I’m reusing the same filter). Any advice?

    Thanks again ??

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