WordPress: Add action for each custom post type
Im looking to add an action for each of the custom post types registered on my WordPress site (when a custom post type is published). Now I could just manually add one for each of the types I have like:
add_action( 'publish_book', 'function_title_to_call' );
开发者_C百科add_action( 'publish_movie', 'function_title_to_call' );
...
But I wanted to ask if there is a way it could be done so its all automated? I tried the following without luck:
$arguments = array(
'public' => true,
'_builtin' => false
);
$all_post_types = get_post_types( $arguments, 'names', 'and' );
foreach ( $all_post_types as $one_post_type ) {
add_action( 'publish_' . $one_post_type, 'function_title_to_call' );
}
Any suggestions?
精彩评论