• Hello,

    I’m trying to send the form data as body parameters to an API, create a new post and insert the data into the said post.

    Could you please provide details on how can I implement this? The form submit flow should be something among the lines: Insert post -> Redirect to new post -> Call custom hook and populate the newly created post with the API’s response.

    Any insight will be highly appreciated!

    With the best wishes,
    Dragos

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor mjhead

    (@mjhead)

    Hi! Yes, really good case! You can do this by using only Insert Post and Call custom hook actions.

    At first you need to setup insert post action with settings you need

    Than add Call a hook action and callback for this hook. Redirect is beter to setup right inside in the hook callback. Here is an example of action setup – https://prntscr.com/1ssud7m and here is an example of callback code with sample API request and redirect – https://gist.github.com/MjHead/6771eaba3adfe250378b4408878e75c5

    Thread Starter vrejiudragos

    (@vrejiudragos)

    Hello Andrey @mjhead,

    Thank you for your response! It was helpful and much appreciated.

    I have one more question. How can I access the value of the Custom Content Type created via the form?

    The inserted post id can be retrieved using $request['inserted_post_id']. How could I retrieve the id of the inserted CCT instead?

    Also, where could I see each key of the $request array?

    Once again, thank you!

    Best regards,
    Dragos

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Call a custom hook’ is closed to new replies.