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.

Populate a field with a custom post type title

  1. Exclusif
    Member

    Hey,

    I'm trying to populate a form field with the title of the post to which the form is attached. The post is a custom post type (using sugar events). I can't seem to get it to work.
    This is the code i'm using in functions.php:

    add_filter('gform_field_value_event_name', 'populate_post_the_title_attribute');
    		function populate_post_the_title_attribute($value){
    	    global $post;
    
    	    $the_title_attribute = get_the_title('title', $post->the_title_attribute);
    
    	    return $the_title_attribute;
    	}

    I also tried using just "the_title" instead of "the_title_attribute", but no luck.

    Would really appreciate some help. Thanks for a great plugin!

    Posted 12 years ago on Wednesday October 3, 2012 | Permalink
  2. I think get_the_title needs a post ID to be able to return anything. Can you change line 5 to this:

    [php]
    $the_title_attribute = get_the_title($post->ID);

    If that does not work, please echo $the_title_attribute to see what it contains, before you try to return it.

    Posted 12 years ago on Wednesday October 3, 2012 | Permalink
  3. Exclusif
    Member

    Fantastic, worked like a charm. Thanks for the great support!

    Posted 12 years ago on Thursday October 4, 2012 | Permalink
  4. You're welcome. Glad that worked for you.

    Posted 12 years ago on Thursday October 4, 2012 | Permalink

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