Created
May 4, 2018 15:39
-
-
Save brianmaierjr/71613b1911cce73949574433cc0814dd to your computer and use it in GitHub Desktop.
ACF Relationship field array to accordion
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 | |
// 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