开发者

WordPress: Add action for each custom post type

开发者 https://www.devze.com 2023-03-25 21:18 出处:网络
Im looking to add an action for each of the custom post types registered on my WordPress site (when a custom post type ispublished).

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消