• Resolved disturbed-pixel

    (@disturbed-pixel)


    Hi hwk-fr!

    I’m using a custom action and would like to fire on submission (just after) so I am using this hook:

    add_action(‘acfe/form/submit/my-custom-action’, ‘my_form_custom_action’, 10, 2);

    I want to use this hook on mulitple forms, thats why i was trying to use the same custom action for all my forms.

    I need to get the “Generated ID” that’s created in the SAVE tab (i’m using for post title) of the Post Action. For the life of me i am not sure how to get it.

    I’ve tried:
    get_field(‘post_title’)
    get_query_var(‘post_title’)
    get_the_title( $post_id ) – brings back the form/page title, not the newly created post

    I also need the permalink and terms of the newly created page

    Please could you point me the right direction?

    Thanks as always!

    • This topic was modified 4 years, 1 month ago by disturbed-pixel. Reason: typo
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    Thanks for the feedback!

    So first, if you’re going to use the same action on multiple forms, you’re not forced to use a “Custom Action”. You can simply use the hook acfe/form/submit/form=my-form which is triggered on submission after all actions are completed. See documentation. It’s not an obligation tho, you can keep using custom actions if you want to.

    You can indeed retrieve all information from any “Post Action” or “Term Action” (your custom action must be added after them tho). Each “Post/Term/User Action” generate a query_var when it has created or updated a post/term/user. The query var name is simply the name of the action.

    For example, if you have a “Post Action”, named my-post-action, which create a new post, you’ll be able to retrieve all the newly created post array with the following code: get_query_var('my-post-action'). This array contain many information, including the post title, permalink, admin link, author information and more!

    You’ll find more information about that feature in the Query Var documentation of each actions.

    Hope it helps!

    Regards.

    Thread Starter disturbed-pixel

    (@disturbed-pixel)

    Thanks hwk-fr! I had been looking at those docs, but didn’t quite understand quite what i was doing wrong.

    Though its not quite working for me. I tried to print out the contents of get_query_var(‘my-form-action-name’) but i am not getting anything. Also each form has a different post action name.

    I’ve gone back to using:

    acfe/form/submit/post and checking the Action and post_type when triggered. So that all forms trigger the hook and i can let specific one’s trigger my code via a simple IF.

    I’ve used a combination of get_field, get_the_terms, get_post_permalink and $args to get all the values i need.

    I know it’s not pretty, but its working. (until i get the time to make something better).

    Thanks

    Plugin Author Konrad Chmielewski

    (@hwk-fr)

    Hello,

    If you’re using a custom action name, the query var will be get_query_var('my-action-name'), not get_query_var('my-form-my-action-name').

    The solution you found using the acfe/form/submit/post hook is okay, it’s just an another way to achieve it ??

    Have a nice day!

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Action get generated ID’ is closed to new replies.