Home › Forums › Front-end Issues › How do you pass in a custom field in a Link? › Reply To: How do you pass in a custom field in a Link?
So, I found the answer. Made this snippet:
// This function runs after your post is saved
function acf_googleLink( $post_id ) {
//Get value of address
$address = get_field( 'address_field_name', $post_id );
//Get value of city
$city = get_field( 'city_field_name', $post_id );
//Get value of state
$state = get_field( 'state_field_name', $post_id );
//Get value of ZIP
$zip = get_field( 'zip_field_name', $post_id );
//Gathers address fields w/ zip
$fullAddress = [$address, $city, $state, $zip];
//Gathers address fields w/o zip
$fullAddressNoZip = [$address, $city, $state];
//Merge full address for text
$merge = implode(", ",$fullAddressNoZip);
//Merge full address for link
$linkMerge = implode(" ",$fullAddress);
//Display the Link
return("<a href='//www.google.com/maps/search/$linkMerge' target='_blank'>$merge $zip</a>");
}
add_shortcode( 'acf_map_link', 'acf_googleLink' );
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.