Creating Custom Merge Tag, like magic_tag from Caldera Forms
-
Hi dear support/community, i wanted to know if there is a way to transfer custom merge tags from caldera forms (since it is no longer a supported plugin) to ninja forms or how to create custom merge tags that get values from the database like in this code example. i basically want to populate a form with an event id with prepopulated data based on the url with an event_id.
add_filter( 'caldera_forms_do_magic_tag', function( $value, $magic_tag ) { if ( $magic_tag == '{my_event_id}' ) { if (empty($_GET['event_id'])) { return ''; } return $_GET['event_id']; } if ( $magic_tag == '{my_workshop_name}' ) { if (empty($_GET['event_id'])) { return ''; } global $wpdb; $amelia_workshop = $wpdb->get_results( "SELECT events.name FROM wp_amelia_events events JOIN wp_amelia_events_periods periods ON events.id = periods.eventId WHERE events.id = " . $_GET['event_id'], OBJECT )[0]; return $amelia_workshop->name; } if ( $magic_tag == '{my_event_date}' ) { if (empty($_GET['event_id'])) { return ''; } global $wpdb; $amelia_workshop = $wpdb->get_results( "SELECT periods.periodStart FROM wp_amelia_events events JOIN wp_amelia_events_periods periods ON events.id = periods.eventId WHERE events.id = " . $_GET['event_id'], OBJECT )[0]; $event_date = $amelia_workshop->periodStart; return date_i18n( get_option( 'date_format' ), strtotime( $event_date ) ); } return $value; }, 10, 2 );
- The topic ‘Creating Custom Merge Tag, like magic_tag from Caldera Forms’ is closed to new replies.