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' );
What I’m trying to do is use a Custom field value as a shortcode in an anchor link. When I submit the code, it doesn’t recognize the URL value.
Lawd have mercy! It works, thank you! Do you have any tips for a breakdown of the code syntax?
Thanks for this. Just to clarify, the ‘field’ should have the name of the Post Object field that I’m targeting the other page.
'field' => 'Post_object'
Then when calling the field on the called page I need to type it in and display it as:
[related_post_acf field=”Field_from_the_target_post”] ?
I wouldn’t know where to start to create a shortcode, how would I link the two so that the Type B data can show up as if it were in Type A?
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.