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.

Inserting newly created post ID into content template?

  1. sascha
    Member

    Hi there,
    is there a way to get the ID of the newly created post into a content template? Basically I would like to send a person an email (text of email comes from a custom field content template) when the post is created and give them the link to the newly created post. I was thinking of getting the post id to do this. But maybe there is an easier, better way?

    Posted 12 years ago on Saturday February 4, 2012 | Permalink
  2. Hi Sascha,

    It doesn't look like the {post_id} merge tag works in the Content Template context. Could you give me some more details on your setup and I'll see if there is something I can cook up for you?

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  3. sascha
    Member

    Hi David,

    I basically have a custom field which is called "message to design office" which can be filled in by the user. The user writes an article about the design office and wants to let them know that he published an article on the website (ID of the created post). The email is sent via a gform after submission hook. So in the content template I would like to use the link to the just created post to let the design office know where they can find the article/post.
    Hope that is clear...

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  4. Hi Sascha,

    If a custom email is being sent via the gform_after_submission hook you can retrieve the created post ID from the $entry object which is passed by the hook.

    [php]
    $post_id = $entry['post_id'];

    Once you have the $post_id you can generate the permalink like so:

    [php]
    $permalink = get_permalink($post_id);

    Add the $permalink variable wherever you'd like it to display in your email.

    Posted 12 years ago on Saturday February 11, 2012 | Permalink
  5. sascha
    Member

    Thanks David,
    will give this a go!

    Posted 12 years ago on Sunday February 12, 2012 | Permalink