Created
December 12, 2023 06:03
-
-
Save ayoubkhan558/fb05f4ef59f5e747813a616e59af89ca to your computer and use it in GitHub Desktop.
Show ACF repeater fields from Product categories in tag taxonomy archive page
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
<?php | |
// Get the current category ID | |
$category_id = get_queried_object_id(); | |
$term = get_queried_object(); | |
$repeaterField = get_field('category_faq', 'product_cat_' . $category_id); | |
// Check if repeater field has values | |
if ($repeaterField) : | |
echo '<ul class="accordion accordionjs">'; | |
$counter = 1; | |
foreach ($repeaterField as $item) : | |
echo '<li class="item acc_section">'; | |
echo '<div class="accordion-header heading acc_head" id="heading' . $counter . '" onclick="toggleAccordion(' . $counter . ')">'; | |
echo '<button class=" acc_button">'; | |
echo esc_html($item['category_faq_question']); | |
echo '<span class="icon dce-accordion-icon accordion-icon-right"><svg aria-hidden="true" class="e-font-icon-svg e-fas-chevron-down" viewBox="0 0 448 512" xmlns="http://www.w3.org/2000/svg"><path d="M207.029 381.476L12.686 187.132c-9.373-9.373-9.373-24.569 0-33.941l22.667-22.667c9.357-9.357 24.522-9.375 33.901-.04L224 284.505l154.745-154.021c9.379-9.335 24.544-9.317 33.901.04l22.667 22.667c9.373 9.373 9.373 24.569 0 33.941L240.971 381.476c-9.373 9.372-24.569 9.372-33.942 0z"></path></svg></span>'; | |
echo '</button>'; | |
echo '</div>'; | |
echo '<div class="accordion-content" id="collapse' . $counter . '">'; | |
echo '<p>' . esc_html($item['category_faq_answer']) . '</p>'; | |
echo '</div>'; | |
echo '</li>'; | |
$counter++; | |
endforeach; | |
echo '</ul>'; | |
endif; | |
?> | |
<script> | |
function toggleAccordion(index) { | |
const content = document.getElementById('collapse' + index); | |
if (content.style.display === 'block') { | |
content.style.display = 'none'; | |
} else { | |
content.style.display = 'block'; | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment