WordPress.org

Ready to get started?Download WordPress

Forums

Hook for publishing of custom post types (1 post)

  1. Gabriel
    Member
    Posted 2 years ago #

    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.]

Topic Closed

This topic has been closed to new replies.

About this Topic