Last active
May 9, 2023 15:58
-
-
Save crawford252/62f736004367b386e15150d7c98481e3 to your computer and use it in GitHub Desktop.
Divi FilterGrid - Trigger Filter Click on Meta Terms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
jQuery(document).ready(function ($) { | |
/* LOAD THE FUNCTION BELOW ON PAGE LOAD */ | |
dfg_trigger_filter_by_term_link(); | |
/* LOAD IT AGAIN AFTER DFG COMPLETES AN AJAX CALL AND THE DOM IS UPDATED */ | |
$(document).on('dfg_after_ajax', function () { | |
dfg_trigger_filter_by_term_link(); | |
}); | |
/* WRAP THE JS YOU WANT TO APPLY ON PAGE LOAD AND AFTER AJAX INTO A FUNCTION */ | |
function dfg_trigger_filter_by_term_link() { | |
$('.dp-dfg-item a').on('click', function (e) { | |
e.preventDefault() | |
var category = $(this).text(); | |
var filter = $('.dp-dfg-taxonomy-level-0').find() | |
$(".dp-dfg-taxonomy-level-0 li a").filter(function () { | |
return $(this).text() === category; | |
}).trigger('click'); | |
}); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment