Support

Account

Home Forums Front-end Issues How do you pass in a custom field in a Link?

Solved

How do you pass in a custom field in a Link?

  • I’ve been trying to figure out how to pass in a custom field with an anchor link.
    I tried using this:

    <a href="[acf field='url']">[acf field="street_address"] [acf field="city"]</a>

    The address fields and the url fields are in the same post. But when the page displays, the text is correct but the link itself just links back to the same page.

  • Pass Thru fields are designed to pass a value from your checkout form to your servers, where you can either store or respond to the data. For example, if you have a checkbox for “Join Mailing List” on your checkout form and you pass this data through as a custom field, your servers can respond by adding the customer to your mailing list.

    While Pass Thru custom fields are configured in the Control Panel, they can only be used to pass data via the API.

  • if you have a checkbox for “Join Mailing List” on your checkout form and you pass this data through as a custom field, your servers can respond by adding the customer to your mailing list.

  • 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.

  • 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' );
    
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.