Support

Account

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' );