Reputation: 63
I have problems to use a hook after a custom post type post (created with "Toolset Types" plugin), post is saved in WP backend.
As a simple example I tried this code:
function test123($post_id){
file_put_contents('test.log',' TEST'."\n",FILE_APPEND);
}
add_action('save_post','test123');
If I save a standard wordpress post, everything works fine and the log is written but if I save a post of my custom post type the log isn't written. Also tried it with the hook "wp_after_insert_post", but it didn't work either...
It does't make sense to me, why this isn't working. Does anybody have an idea what the problem is?
Upvotes: 0
Views: 1331
Reputation: 432
The save_post
hook only fires for WordPress' default post and page types. You'll need to use a custom hook (save_post_<post_type_slug>
) for your custom post type, based on its slug/registered name.
If your custom post type is something like property_listing
, then you'll need to call save_post_property_listing
, like so:
add_action('save_post_property_listing', 'test123');
More info on the Wordress Developer Code Reference
Upvotes: 1