Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brianmaierjr/71613b1911cce73949574433cc0814dd to your computer and use it in GitHub Desktop.
Save brianmaierjr/71613b1911cce73949574433cc0814dd to your computer and use it in GitHub Desktop.
ACF Relationship field array to accordion
<?php
// create an empty array
$home_faqs = array();
// get list of posts
$home_faqs_posts = get_field('relationship_field_name');
if( $home_faqs_posts ) {
foreach( $home_faqs_posts as $post) {
// variable must be called $post (IMPORTANT)
setup_postdata($post);
// add faq to the list
$home_faqs[] = array( 'title' => get_the_title(), 'content' => get_the_content() );
}
tlh_accordion( $home_faqs );
}
wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment