slaFFik
9/26/2017 - 1:23 PM

WPForms: Process own smart tag (smarttag) with custom value

WPForms: Process own smart tag (smarttag) with custom value

<?php

add_filter( 'wpforms_smart_tag_process', function ( $content, $tag ) {

	// CHANGE custom_tag TO YOUR OWN SMART TAG NAME.
	preg_match_all( '/custom_tag="(.+?)"/', $tag, $ids );

	if ( ! empty( $ids[1] ) ) {
		foreach ( $ids[1] as $key => $item_id ) {
			// CHANGE HERE WHAT YOU WANT TO GET.
			$value = get_post_field( 'post_title', (int) $item_id );
			//$value = get_post_meta( (int) $item_id, '_amount', true );

			$content = str_replace( '{custom_tag="' . $item_id . '"}', $value, $content );
		}
	}

	return $content;
}, 10, 2 );