Support » Fixing WordPress » Hook for publishing of custom post types

  • Gabriel


    Hey everyone!

    I am trying to hook into whenever a custom post type is published with my own function. It of course works if I add an action to each post type I got manually, typing out all currently registered types but I want to know if it is possible to code it so any future new post types are automatically included?

    Example (which does not work):

    $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_name_to_call' );

    [Please post code snippets between backticks or use the code button.]

  • The topic ‘Hook for publishing of custom post types’ is closed to new replies.