Forums

Hook for publishing of custom post types (1 post)

  1. designbymerovingi
    Member
    Posted 10 months 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.]

Reply

You must log in to post.

About this Topic

  • RSS feed for this topic
  • Started 10 months ago by designbymerovingi
  • This topic is not resolved
  • WordPress version: 3.2.1