• Resolved websim

    (@websim)


    Hi
    I want to create a filter similar to this

    In the example, filters work on tags and categories but I want to filter taxonomies and taxonomy terms.

    I tried the code below but it does not work
    How can I fix it?
    Thanks

    <!--test filter-->
    <ul class="advanced-filter-menu" data-type="radio" data-parameter="taxonomy">
     <li>
      <input id="cat-studi" name="radio-group" value="my_taxonomy" type="radio">
      <label for="cat-studi">My taxonomy</label>
     </li>
    </ul>
    <select class="advanced-filter-menu" data-type="select" data-parameter="taxonomy_terms">
     <option value="conservatore">My taxonomy terms</option>
    </select>
    <button type="button" class="submit btn btn-readmore mt-40 mb-40" id="apply-filters"><i class="fa fa-check"></i> Apply Filters</button>
    
Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Darren Cooney

    (@dcooney)

    Hi @websim,
    What doesn’t work about it? Can you be a bit more specific…. Is the JS firing?

    Let me know.
    Cheers,

    Thread Starter websim

    (@websim)

    Hi

    I get the following error “ReferenceError: alm_is_animating is not defined”
    here my code js

    	jQuery(document).ready(function ($) {
    
    	function alm_adv_filter(){
    	
    		if(alm_is_animating){
    			return false; // Exit if filtering is still active 
    		}
    		
    		alm_is_animating = true;
    		
    		var obj= {}, 
    			 count = 0;
    		
    		// Loop each filter menu
    		$('.advanced-filter-menu').each(function(e){
    			var menu = $(this),
    			    type = menu.data('type'), // type of filter elements (checkbox/radio/select)
    			    parameter = menu.data('parameter'), // category/tag/year
    			    value = '',
    			    count = 0;
    			
    			// Loop each item in the menu      	
    			if(type === 'checkbox' || type === 'radio'){ // Checkbox or Radio
    				$('input:checked', menu).each(function(){
    					count++;
    					var el = $(this);
    				
    					// Build comma separated string of items
    					if(count > 1){
    						value += ','+el.val();
    					}else{
    						value += el.val();
    					}	
    				});
    			}
    		
    			if(type === 'select'){ // Select
    				var select = $(this);
    				value += select.val();
    			}
    		
    			obj[parameter] = value; // add value(s) to obj
    			
    		});
    		
    		console.log(obj);
    		
    		var data = obj;      
    		$.fn.almFilter('fade', '300', data); // Send data to Ajax Load More
    	}
    	
    	$('#apply-filters').on('click', alm_adv_filter); // 'Apply Filter' button click
    	
    	/*
    	* almFilterComplete()
    	* Callback function sent from core Ajax Load More
    	*
    	*/
    	$.fn.almFilterComplete = function(){      
    		alm_is_animating = false; // clear animating flag
    	};
    
    	});
    Plugin Author Darren Cooney

    (@dcooney)

    Just define that function at the top.
    Like this.

    jQuery(document).ready(function ($) {
    	
    	var alm_is_animating = false;
    	
    	function alm_adv_filter(){
    	
    		if(alm_is_animating){
    			return false; // Exit if filtering is still active 
    		}
    		
    		alm_is_animating = true;
    		
    		var obj= {}, 
    			 count = 0;
    		
    		// Loop each filter menu
    		$('.advanced-filter-menu').each(function(e){
    			var menu = $(this),
    			    type = menu.data('type'), // type of filter elements (checkbox/radio/select)
    			    parameter = menu.data('parameter'), // category/tag/year
    			    value = '',
    			    count = 0;
    			
    			// Loop each item in the menu      	
    			if(type === 'checkbox' || type === 'radio'){ // Checkbox or Radio
    				$('input:checked', menu).each(function(){
    					count++;
    					var el = $(this);
    				
    					// Build comma separated string of items
    					if(count > 1){
    						value += ','+el.val();
    					}else{
    						value += el.val();
    					}	
    				});
    			}
    		
    			if(type === 'select'){ // Select
    				var select = $(this);
    				value += select.val();
    			}
    		
    			obj[parameter] = value; // add value(s) to obj
    			
    		});
    		
    		console.log(obj);
    		
    		var data = obj;      
    		$.fn.almFilter('fade', '300', data); // Send data to Ajax Load More
    	}
    	
    	$('#apply-filters').on('click', alm_adv_filter); // 'Apply Filter' button click
    	
    	/*
    	* almFilterComplete()
    	* Callback function sent from core Ajax Load More
    	*
    	*/
    	$.fn.almFilterComplete = function(){      
    		alm_is_animating = false; // clear animating flag
    	};
    
    });
    Thread Starter websim

    (@websim)

    Ok no error now and this is the object of the browser console:
    Object {post_type: "architetti", taxonomy: "categorie_architetti", taxonomy_terms: "architetto"}

    But the filter is ignored and all posts are shown

    Plugin Author Darren Cooney

    (@dcooney)

    Right, well that makes sense because the advanced filter is not set up for multiple tax args because those args are passed in differently then multiple cats or tags.

    In ALM, you pass multiple taxonomy terms to the query like this:
    [ajax_load_more taxonomy="tax_1:tax_2" taxonomy_terms="term_1, term_2:term_3" taxonomy_operator="IN:IN" taxonomy_relation="OR"]

    Are you using multiple taxonomies or just multiple terms?

    Cheers,

    Thread Starter websim

    (@websim)

    I’m using multiple taxonomies

    Plugin Author Darren Cooney

    (@dcooney)

    Ok. Multiple taxonomies will require custom development..
    The example on the site is really just an example of what you can do with filtering… but you’re going to need to adjust that function to accept the required parameters for tax queries.

    Thread Starter websim

    (@websim)

    Thanks dcooney
    Can you help me with the script?

    Plugin Author Darren Cooney

    (@dcooney)

    Hi @websim,
    If I get some time I can, but not sure if I will this week.

    Thread Starter websim

    (@websim)

    Thank you very much, but I solved with default category of wordpress (As in your demo).

    I also want to integrate search in filters is it possible?

    Plugin Author Darren Cooney

    (@dcooney)

    Yea, you could that. Again, this would require custom coding to the JS.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Multiple filters by taxonomy terms’ is closed to new replies.