Skip to content

Instantly share code, notes, and snippets.

@slaFFik
Last active April 14, 2020 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaFFik/b2bb2a28d9885b3bd5b589b4392a8803 to your computer and use it in GitHub Desktop.
Save slaFFik/b2bb2a28d9885b3bd5b589b4392a8803 to your computer and use it in GitHub Desktop.
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 );
@Aljafark
Copy link

Hello,

Can we use this to Display some values of fields or custom columns which i added myself to the wpforms_entries? I mean can we use the smart tag to retrieve something from the database that doesn't have a function like get_post_meta() get_title() etc?

@slaFFik
Copy link
Author

slaFFik commented Apr 14, 2020

@Aljafark Yes, you can.
Instead of $value = get_post_field( 'post_title', (int) $item_id ); usage, you will need to use $wpdb global variable to make custom requests to the DB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment