Currently, I have this script:
<?php $test = get_categories('taxonomy=item&type=things');?>
<?php foreach($test as $stuff) : ?>
<script type="text/javascript">
jQuery(document).ready(function($) {
var $things = <?php echo json_encode($stuff->name); ?>;
console.log($things);
$(".element").each(function() {
var $state = $(this).attr("title");
if ($things.indexOf($state) > -1) {
$(this).addClass('current');
}
});
});
</script>
<?php endforeach; ?>
Which is working, but I'm not sure how to get it out of the foreach loop so that it doesn't keep repeating the jQuery script over and over again.
Overall, I'm trying to get the values out from the get_categories via WordPress, but then pass the name value from the array and then check that within jQuery to add a class to specific elements within a div.
I know I'm probably going about the wrong way, so I'm completely open to suggestion if anyone knows a better, cleaner way of approaching this.
$has_executed = false) which can be toggled.foreachloop or somewhere else?