Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Last active March 19, 2020 16:37
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 leepettijohn/33621067d6ba649a7b9baeb55cbbb3bb to your computer and use it in GitHub Desktop.
Save leepettijohn/33621067d6ba649a7b9baeb55cbbb3bb to your computer and use it in GitHub Desktop.
Gravity Forms - dynamically populate fields
<?php
/* *** replace "your_parameter" with the parameter in the advanced tab
https://docs.gravityforms.com/using-dynamic-population/ */
add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
function my_custom_population_function( $value ) {
return 'boom!';
}
/*Use this for a real estate form */
add_filter( 'gform_field_value_property_name', 'wap_populate_post_title' );
function wap_populate_post_title( $value ) {
// bail if we aren't on a single listing CPT
if ( ! is_singular( 'listing' ) ) {
return;
}
// fetch the post title
$title = get_the_title();
// return value escaped
return esc_html( $title );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment