Support

Account

Home Forums General Issues WPForms Custom Smart Tag with ACF Link Field in Array

Solved

WPForms Custom Smart Tag with ACF Link Field in Array

  • Hi,

    I’m currently trying to set up a custom smart tag on WP Forms using an ACF Link Type Field setup with Array.

    This process works fine for text based fields, but I’m having problems returning any value because it’s a link field and therefore need to capture URL value.

    For extra context, the WP Form is inside a single product page, and it should capture the value, but I can’t seem to get it to work. The field I’m trying to default fill with a smart tag just remains blank.

    Any advice would be much appreciated.

    Thanks

    Snippet…

    if ("home_report_url" === $tag) {
            $homereportlink = get_field_object("home_report_url", get_the_ID());
    		if($homereportlink) {$home_link_url = $homereportlink['url'];}
            $content = str_replace("{home_report_url}", $home_link_url, $content);
        }

    Full Code…

    function wpf_dev_register_smarttag($tags) {
    $tags["home_report_url"] = "Home Report URL";
        return $tags;
    }
    add_filter("wpforms_smart_tags", "wpf_dev_register_smarttag");
    function wpf_dev_process_smarttag($content, $tag) {
    	if ("home_report_url" === $tag) {
            $homereportlink = get_field_object("home_report_url", get_the_ID());
    		if($homereportlink) {$home_link_url = $homereportlink['url'];}
            $content = str_replace("{home_report_url}", $home_link_url, $content);
        }
        return $content;
    }
    add_filter("wpforms_smart_tag_process", "wpf_dev_process_smarttag", 10, 2);
  • Sorry for any confusion but I managed to get it working.

    if ("home_report_url" === $tag) {
    		$homereportlink = get_field("home_report_url", get_the_ID());
    		if( $homereportlink ): $home_link_url = $homereportlink['url'];
    		$content = str_replace("{home_report_url}", $home_link_url, $content);
    		endif;
        }
    return $content;
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.