Created
May 17, 2019 17:42
-
-
Save Garconis/664034b02be04fb27aabef097cf7ff91 to your computer and use it in GitHub Desktop.
WordPress | ACF Repeater Field output with shortcode
This file contains hidden or 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 | |
// ACF Group Shortcode | |
function shortcode_acf_find_my_flowers( $atts ) { | |
// begin output buffering | |
ob_start(); | |
if( have_rows('where_to_find_my_flowers') ) { | |
echo '<ul class="where-to-find-my-flowers-address-wrapper">'; | |
while ( have_rows('where_to_find_my_flowers') ) : the_row(); | |
// vars | |
$company_name = get_sub_field('company_name'); | |
$address_street = get_sub_field('additional_physical_address_street'); | |
$address_city = get_sub_field('additional_physical_address_city'); | |
$address_state = get_sub_field('additional_physical_address_state_province'); | |
$address_zip = get_sub_field('additional_physical_address_postal_code'); | |
$address_country = get_sub_field('additional_physical_address_country'); | |
$google_maps_url = 'https://www.google.com/maps/dir//'. $company_name .', '. $address_street .', '. $address_city .', '. $address_state .' '. $address_zip .' '. $address_country; | |
echo '<li>'; | |
if( $company_name ) { | |
echo '<h6 class="where-to-find-my-flowers-company">'. $company_name .'</h6>'; | |
} | |
if( $address_street ) { | |
echo '<span class="where-to-find-my-flowers-address-street">'. $address_street .'</span><br>'; | |
} | |
if( $address_city ) { | |
echo '<span class="where-to-find-my-flowers-address-city">'. $address_city .'</span>, '; | |
} | |
if( $address_state ) { | |
echo '<span class="where-to-find-my-flowers-address-state">'. $address_state .'</span> '; | |
} | |
if( $address_zip ) { | |
echo '<span class="where-to-find-my-flowers-address-zip">'. $address_zip .'</span><br>'; | |
} | |
if( $address_country ) { | |
echo '<span class="where-to-find-my-flowers-address-country">'. $address_country .'</span>'; | |
} | |
echo '<a href="'. $google_maps_url .'" target="_blank" class="where-to-find-my-flowers-directions">Get Directions</a>'; | |
echo '</li>'; | |
endwhile; | |
echo '</ul>'; | |
} | |
else { | |
echo 'No locations currently set.'; | |
} | |
// end output buffering, grab the buffer contents, and empty the buffer | |
return ob_get_clean(); | |
} | |
add_shortcode( 'acf_find_my_flowers_addresses', 'shortcode_acf_find_my_flowers' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment