Skip Navigation

[Resolved] Testing for post type instead of using post ID

This support ticket is created 6 years, 12 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by susanB-3 6 years, 12 months ago.

Assisted by: Shane.

Author
Posts
#519875

I asked this question in a different thread with Minesh but went ahead and set that one as "resolved" to not muddy the issues. The question is independent of that specific problem.

When writing functions, is there a way to test if a certain type of post is being created rather than limiting code to certain forms? For example if I have a post type called "funeral notice" and I only want a function to run whenever "funeral notice" is created or edited, is that possible?

#519891

Shane
Supporter

Languages: English (English )

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

Hi Susan,

Thank you for contacting our support forum.

Actually yes this is possible by using the save_post hook by checking the post type when the post is being created.

Take a look at the link below specifically the Book example
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

This should be a suitable example to get you up to speed with this.

Thanks,
Shane

#519907

Thank you very much Shane!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.