• Resolved Giang Le

    (@gianghl1983)


    Hi,

    I am using action Save to make a new post after form submitted. I see that we can select Generated ID for Post Type, Post Slug…

    My question are:

    1/ How to return that ID for clients after they submit in the “Post Updated” Message. So they can use that as tracking ID for the submited form. E.g: “Post Updated, your tracking ID is #239” in which 239 is generated ID.
    2/ How can I map Generated ID to a ACF’s custom field (a hidden one, not show for client, just used for making filter system later on).

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback. The Generated ID is simply the actual Post ID.

    1/ In order to retrieve the Post ID of the created post, you have to set a custom action name in your “Post Action”. Once you’ve set a custom name, you have to enable the “Query Var” switch.

    This will create a new template tags {query_var:my-action-name:ID}, {query_var:my-action-name:post_title} etc… You’ll find a list of all available template tags for the post creation in the “Cheatsheet” tab. In your case, you have to use {query_var:my-action-name:ID} in the success message.

    Note: You have to leave the “Redirection” field blank, because query var cannot be used in conjonction with redirection.

    Here is a screenshot example: https://i.imgur.com/vn3kALc.png

    2/ As the generated ID is simply the Post ID, you can use update_field() on Post Save, using the following hook:

    
    /**
     * @int     $post_id    The targeted post ID
     * @string  $type       Action type: 'insert_post' or 'update_post'
     * @array   $args       The generated post arguments
     * @array   $form       The form settings
     * @string  $action     The action alias name
     *
     * Note: At this point the post & meta fields are already saved in the database
     */
    add_action('acfe/form/submit/post/action=my-action', 'my_form_post_save', 10, 5);
    function my_form_post_save($post_id, $type, $args, $form, $action){
        
        /*
         * Add the Post ID in a custom field
         */
        update_field('my_field', $post_id, $post_id);
        
    }
    

    See the “Advanced” tab in Post Action for more hook examples.

    Hope it helps!

    Have a nice day.

    Regards.

    Thread Starter Giang Le

    (@gianghl1983)

    @hwk-fr Thank you!

    It helps me a lot.

    Have a wonderful day!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Include Generated ID in Updated Message?’ is closed to new replies.