Skip Navigation

[Resolved] How to check for Pending->Publish status for CPT in PHP?

This support ticket is created 5 years, 6 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by jeffS-2 5 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1240064

I have a CRED form that is an application for new membership. When the form is submitted, it creates a new member's profile CPT post and sets it to "Pending" status. An admin must then review the application before accepting it and Publishing the new member's profile. When the status switches to "Published," I need to trigger another function in PHP. Assuming I can do this using post_save_data, how do I check for the CPT post_type and status=Published?

#1240153

Hello,

I suggest you try with WordPress Post Status Transitions action hook, for example:

function on_publish_pending_post( $post ) {
    // A function to perform when a pending post is published.
    if(get_post_type($post) == 'MY-CPT'){
// here do something ...
    }
}
add_action(  'pending_to_publish',  'on_publish_pending_post', 10, 1 );

More help:
https://codex.wordpress.org/Post_Status_Transitions
https://developer.wordpress.org/reference/functions/get_post_type/

#1242438

My issue is resolved now. Thank you!