Skip to content

Instantly share code, notes, and snippets.

@DMSpeed
Created September 5, 2017 22:53
Show Gist options
  • Save DMSpeed/7438bbd27baf6e3d29d455cc491cbcc4 to your computer and use it in GitHub Desktop.
Save DMSpeed/7438bbd27baf6e3d29d455cc491cbcc4 to your computer and use it in GitHub Desktop.
FAQ page built with Advanced Custom Fields (based on WPBeaches)
<?php
/*
Template Name:FAQ Page
*/
//Thanks to WPBeaches for this code: https://wpbeaches.com/creating-a-faq-page-in-wordpress-using-acf-and-jquery/
add_action( 'genesis_entry_content', 'wpb_faq_repeater_page', 10 );//Position FAQs after post content
function wpb_faq_repeater_page () {
//My ACF Fields for reference
//faqs - field group
//faq_question - sub-field
//faq_answer - sub-field
// check if the repeater field has rows of data
if( have_rows('faq') ):
// loop through the rows of data
while ( have_rows('faq') ) : the_row();
// display a sub field value
echo'<div id="faq_container">
<div class="faq">
<div class="faq_question"> <span class="question">' . get_sub_field('faq_question') . '</span><span class="accordion-button-icon fa fa-plus"></span></div>
<div class="faq_answer_container">
<div class="faq_answer"><span>' . get_sub_field('faq_answer') . '</span></div>
</div>
</div>
</div>';
endwhile;
else :
// no rows found
endif;
}
genesis();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment