admin管理员组

文章数量:1316323

I'm using the wp-types plugin to create a custom post type. I'm developing my own plugin which I need to fire whenever a post of my custom post type is updated.

Right now add_action( 'save_post', 'myFunc'); will fire if a regular post is updated, however not if one of of the custom posts is updated.

Does anyone know why this might be? Thanks!

I'm using the wp-types plugin to create a custom post type. I'm developing my own plugin which I need to fire whenever a post of my custom post type is updated.

Right now add_action( 'save_post', 'myFunc'); will fire if a regular post is updated, however not if one of of the custom posts is updated.

Does anyone know why this might be? Thanks!

Share Improve this question asked May 11, 2015 at 18:51 James MyersJames Myers 155 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Try this way:

    add_action( 'save_post', 'myFunc');
function myFunc(){
if ($post->post_type == 'cpt' ) {
// do action here
}

OR

add_action( 'save_post', 'myFunc');
function myFunc(){
if ( 'cpt' == get_post_type() ) {
// do action here
}

本文标签: Types plugin custom post addaction hooks