Skip Navigation

[Resolved] Which hook fires after meta data and custom taxonomy have been saved

This support ticket is created 2 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 8 replies, has 2 voices.

Last updated by matthiasI 2 years, 3 months ago.

Assisted by: Shane.

Author
Posts
#2456277

Tell us what you are trying to do?

Find the right hook to perform action after post has been created. I need the taxonomy and the post meta to be already saved.

I have tried with "save_post" and "wp_after_insert_post" (priority 100) but the Toolset post meta aren't saved at this point.

#2456415

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

Thanks for getting in touch. I did a search on the wordpress codex and was able to find this hook below.
https://developer.wordpress.org/reference/hooks/post_updated/

Please let me know if this helps.
Thanks,
Shane

#2456955

Hello Shane,

Thank you for your reply.
I have tried this hook but it seems to append before the meta data from Toolset are saved.
This is the only meta that are saved when I call this hook :
(
[_edit_lock] => Array
(
[0] => 1663142585:1
)
)

There are other people struggling with this point on the Toolset support forum. This is what I have read and tried so far with no success :
https://toolset.com/forums/topic/unable-to-update-fields-value-programatically-on-save_post/
https://toolset.com/forums/topic/update_post_meta-on-save-not-updating/

I have spend the whole day yesterday trying to find the right hook.
That's why I'm calling on your help now.

#2457261

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

Perhaps we can find an alternative what exactly are you trying to do ? Is it that you want to interact with the values of the custom fields and taxonomy when the post is being saved?

I've checked around and wasn't able to find a suitable hook.

Please let me know so I can see if an alternative is possible.

Thanks,
Shane

#2457381

Shane,

Thank you for your reply.

Here is what I'm trying to do.

When a specific custom post type is created,
I need to send a notification to a certain group of users, based on a taxonomy of the new post.
I want to send this notification just once.

The problem with the "save_post", "post_updated" and "wp_after_insert_post" is that the parameter "updated" which is supposed to inform if the post is created or updated is "buggy", it is always true whatever the situation.
So I have created a new meta "wpcf-notification-send" that I want to update as "true" when I have send the notification.
But if I update this meta within the before mentioned hooks, it is overwrite by Toolset because the hooks append before the meta are saved.

That leads to my question "Which hook fires after meta data and custom taxonomy have been saved ?"

If you see another solution I'm all ears 🙂

#2457513

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

I'm unsure of the hook that does this, however I do know with our Toolset forms plugin you can setup the notifications with the custom field values. This will require that you create your posts on the frontend using the Post Forms.

However based on what I see here you're creating the posts on the backend. Why not intercept the POST request for the creation to get the values from that request to push to your notifications.

Let me know if this can work for you.

Thanks,
Shane

#2457543

Hi Shane,

I did not go in depth in my explanations but the notificationq I need are send to mobile app users through OneSignal, I'm pretty sure it's different from the notifications Toolset is sending from the frontend Post Forms.

I would love to know how to intercept the POST request 😍. Could you explain me how to do that ?

#2457553

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Matthias,

Given that the custom fields will be provided in the POST payload then you should be able to get them like this
$_POST['wpcf-my-field']

If that doesn't work then you can try the exact format of the post request variable
$_POST['wpcf[field-slug]']

Please let me know if this helps.
Thanks,
Shane

#2457867

Hi Shane, my issue is resolved now.

I finally used the wp_after_insert_post hook.
To determine if it was a post creation or an update, I checked the existence of a toolset meta. If it doesn't exist : creation, if it already exist : update