Skip to content

Instantly share code, notes, and snippets.

@cdils
Last active May 29, 2019 14:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cdils/10124803 to your computer and use it in GitHub Desktop.
Save cdils/10124803 to your computer and use it in GitHub Desktop.
Add a Gravity Forms to a single AgentPress Listings post and dynamically populate the form with the post title. Add this to functions.php.
<?php //remove this line
/**
* Enqueue scripts for a specified Gravity Form (13 = ID) and then
* embed Gravity Form at the bottom of single property listings
*
* http://www.gravityhelp.com/documentation/page/Gform_enqueue_scripts
* http://www.gravityhelp.com/documentation/page/Embedding_A_Form#Function_Call
*
* @author Carrie Dils
* @link http://www.carriedils.com/
*/
// Add scripts for Gravity Forms with ID 13
gravity_form_enqueue_scripts( 13, true );
// Call function to add form to bottom of the entry
add_action( 'genesis_entry_footer', 'wap_add_contact_form', 5 );
// Return Gravity Form with specified ID to single listing CPT
function wap_add_contact_form() {
// bail if we aren't on a single listing CPT
if ( ! is_singular( 'listing' ) ) {
return;
}
// display Gravity Form with ID 13
gravity_form( 13, true, false, false, '', false );
}
<?php //remove this line
/**
* Return title of current post for single property listing
* Dynamic population for Gravity Forms (dynamic population parameter = property_name)
* http://www.gravityhelp.com/documentation/page/Using_Dynamic_Population
*
* @author Carrie Dils
* @link http://www.carriedils.com/
*/
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