I'm trying to load some code depending on which portfolio category i am , but cant seem to get it quite right...
I've read that portfolio categories are called taxonomies, but don't know if thats right..
tried this code in my functions.php
but crashed my whole site!
add_action('wp_footer', 'ava_auto_click');
function ava_auto_click(){
$the_terms = get_the_terms( $post->ID , 'portfolio_entries');
for ($i=0;$i< count($the_terms); ++$i) {
var_dump($the_terms[$i]);
if($the_terms[$i] =="projects"){
?>
<script>
window.onload = function(){
var elem = document.querySelector('.wrap-filter').querySelectorAll('li')
var event = new Event('click');
document.getElementById('projects').classList.remove('none')
elem[0].setAttribute("data-filter", ".offices, .retail, .residential, .stands, .cultural");
elem[0].firstElementChild.setAttribute("data-filter", ".offices, .retail, .residential, .stands, .cultural");
elem[1].classList.toggle('active')
elem[1].querySelector('a').click();
}
</script>
<?php
}
else {
?>
<script>
window.onload = function(){
var elem = document.querySelector('.wrap-filter').querySelectorAll('li')
var event = new Event('click');
document.getElementById('projects').classList.remove('none')
elem[1].classList.toggle('active')
elem[1].querySelector('a').click();
}
</script>
<?php
}
}
}
Thanks in advance for the help!!
I think the main structure is right but the if
and the $the_terms = get_the_terms( $post->ID , 'portfolio_entries');
might be wrong