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.

Pulling a Custom Field from a different post to Notification Space

  1. Does anyone know how to format line 3 of this, I pulled the rest from another forum post, but I am pretty terrible with php and couldn't get that line to work right:

    add_filter( 'gform_notification_email_X', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	$post->2;
    	$email_to = types_render_field("email", array("raw"=>"false")));
    	return $email_to;
    }

    To clarify I am trying to pull a custom field (email) from a custom post type profile page in to the notification email box.

    Posted 12 years ago on Monday July 16, 2012 | Permalink
  2. You need to determine how the email address is stored and where, then we can help you figure out how best to format this code. So far, we don't have enough information. Can you tell us how the email address is stored? Normally, it would be in the post meta table. If that is true, we need to know the meta key, and then need the post ID, and we can grab the value and show you how to use it here.

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  3. I was trying to pull from post Id 2 and from "types_render_field("email")" which is the custom meta field. I was not sure how to properly format those two.

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  4. Is this the plugin you are using?

    http://wordpress.org/extend/plugins/types/

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  5. If the meta key in your wp_postmeta is indeed types_render_field("email") then you can grab the meta value from that key, with post ID 2, like this:

    get_post_meta(2, 'types_render_field("email")', true);

    You may have to escape the ( and " in the meta key name (but I don't think so.) Does that work for you?

    Posted 12 years ago on Tuesday July 17, 2012 | Permalink
  6. I wasn't able to get a notification to come through. To make sure we are on the same page here is the code I was using:

    add_filter( 'gform_notification_email_1', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	$email_to = get_post_meta(2, 'types_render_field("email", array("raw"=>"false"))', true);
    	return $email_to;
    }
    Posted 12 years ago on Wednesday July 18, 2012 | Permalink
  7. Based on the code you posted, this is the meta key?

    types_render_field("email", array("raw"=>"false"))

    That whole thing exists as the meta key in the wp_postmeta table? Can you post a screenshot of the wp_postmeta table record where this value exists, using something like phpMyAdmin? It seems unlikely that that is the actual meta key but I would just like to confirm. Thank you

    Posted 12 years ago on Wednesday July 18, 2012 | Permalink
  8. Sorry for the slow reply

    That is syntax for the Types api (http://wp-types.com/documentation/functions/)

    The meta key in my db was actually "wpcf-email"

    Posted 12 years ago on Wednesday July 18, 2012 | Permalink
  9. That worked!

    That was my mistake. I was putting in the wrong piece. It works when using that meta key.

    Here is the final code:

    add_filter( 'gform_notification_email_1', 'route_notification', 10, 2 );
    function route_notification($email_to, $entry) {
    	$email_to = get_post_meta(2, 'wpcf-email', true);
    	return $email_to;
    }

    [EDITED by Chris Hajer
    to change value of meta key from meta-key to wpcf-email]

    Posted 12 years ago on Wednesday July 18, 2012 | Permalink
  10. David Peralty

    Glad you were able to sort it out.

    Posted 12 years ago on Wednesday July 18, 2012 | Permalink

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