Skip to content

Instantly share code, notes, and snippets.

@ayoubkhan558
Created December 12, 2023 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayoubkhan558/cec3901541952152aeffd53d4ef042ef to your computer and use it in GitHub Desktop.
Save ayoubkhan558/cec3901541952152aeffd53d4ef042ef to your computer and use it in GitHub Desktop.
Show ACF repeater fields from Product taxonomy in tag taxonomy archive page
<?php
// Get the current tag
$tag = get_queried_object();
// Check if the tag exists
if ($tag) {
// Get ACF repeater field values for the current tag
$repeaterField = get_field('product_tag_faq', 'product_tag_' . $tag->term_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['product_tag_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['product_tag_answer']) . '</p>';
echo '</div>';
echo '</li>';
$counter++;
}
echo '</ul>';
}
}
?>
<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