Last active
April 14, 2020 07:08
-
-
Save slaFFik/b2bb2a28d9885b3bd5b589b4392a8803 to your computer and use it in GitHub Desktop.
WPForms: Process own smart tag (smarttag) with custom value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 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
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?