Skip to content

Instantly share code, notes, and snippets.

@leepettijohn
Created November 16, 2015 16:52
Show Gist options
  • Select an option

  • Save leepettijohn/9fb0dbe43a0593b9ce7d to your computer and use it in GitHub Desktop.

Select an option

Save leepettijohn/9fb0dbe43a0593b9ce7d to your computer and use it in GitHub Desktop.
Automatically Populate Gravity Forms from Posts, Events, etc.
// Add scripts for Gravity Forms
gravity_form_enqueue_scripts( [gformid], true );
// Call function to add form to bottom of the entry
// *** This only works if you're using a Genesis theme ***
add_action( 'genesis_entry_footer', 'add_form_to_bottom', 5 );
// Return Gravity Form with specified ID to single listing CPT
function add_form_to_bottom() {
// bail if we aren't on a single listing CPT
// Change 'listing' to post type
if ( ! is_singular( 'listing' ) ) {
return;
}
// display Gravity Form
gravity_form( [gformid], true, false, false, '', false );
}
//use "gform_field_value_[parameter-name]"
add_filter( 'gform_field_value_property_name', 'populate_post_title' );
function populate_post_title( $value ) {
// bail if we aren't on a single listing CPT
// Change 'listing' to post type
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