PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Hook or Filter to populate description with post content?

  1. Is there a way to retrieve a posts content and populate it in the field description (specifically a checkbox field description?

    I would like to populate the description with the formatted content from a post.

    I didn't see anything in the documentation, but I may be missing it.


    Posted 11 years ago on Monday March 19, 2012 | Permalink
  2. Hi, WebEndev,

    I am not sure I understand what you mean, could you explain a bit more? Are you loading a form and populating it with information from an existing post and want what was submitted in a Post Body field to be displayed as the description for your checkbox field on this new form?

    Posted 11 years ago on Monday March 26, 2012 | Permalink
  3. Yes, exactly. But keep the post formatting...

    Posted 11 years ago on Monday March 26, 2012 | Permalink
  4. Hi, WebEndev,

    Below is an example of pulling the content for an existing post and using that content as the description for a form field. I use the WordPress function get_post to pull out the content - . I also use the Gravity Forms hook "gform_pre_render" - . Change the code to reference your post id and field id. You may also set which form you want to apply this code to by using gform_pre_render_1 (add the form id to the hook).

    add_filter("gform_pre_render", "populate_description");
    function populate_description($form)
    	$id = 142; //post id
    	$post = get_post($id); //WordPress get_post function
    	$content = $post->post_content;
    	//loop through fields on form
    	//to get the field for which you want to alter the description
    	foreach($form["fields"] as &$field)
            //change the description for field 2
            if($field["id"] == 2){
                $field["description"] = $content;
    	//return altered form
    	return $form;
    Posted 11 years ago on Tuesday March 27, 2012 | Permalink

This topic has been resolved and has been closed to new replies.