• Как в wordpress отследить создание записи?

    Загляните в файл wp_includes/post.php и найдите там функцию wp_insert_post() вней много интересного, а в самом ее конце есть хуки которые Вы можете использовать.
    /**
    	 * Fires once a post has been saved.
    	 *
    	 * The dynamic portion of the hook name, `$post->post_type`, refers to
    	 * the post type slug.
    	 *
    	 * @since 3.7.0
    	 *
    	 * @param int     $post_ID Post ID.
    	 * @param WP_Post $post    Post object.
    	 * @param bool    $update  Whether this is an existing post being updated or not.
    	 */
    	do_action( "save_post_{$post->post_type}", $post_ID, $post, $update );
    
    	/**
    	 * Fires once a post has been saved.
    	 *
    	 * @since 1.5.0
    	 *
    	 * @param int     $post_ID Post ID.
    	 * @param WP_Post $post    Post object.
    	 * @param bool    $update  Whether this is an existing post being updated or not.
    	 */
    	do_action( 'save_post', $post_ID, $post, $update );
    
    	/**
    	 * Fires once a post has been saved.
    	 *
    	 * @since 2.0.0
    	 *
    	 * @param int     $post_ID Post ID.
    	 * @param WP_Post $post    Post object.
    	 * @param bool    $update  Whether this is an existing post being updated or not.
    	 */
    	do_action( 'wp_insert_post', $post_ID, $post, $update );


    Первый из них позволит Вам сразу получать только Ваши типы записей. А параметр update подскажет Вам новая запись это или нет.
    Ответ написан
    Комментировать
  • Как в wordpress отследить создание записи?

    bingumd
    @bingumd
    ...
    Примерно так:

    add_action(  'publish_post', 'my_new_function', 10, 2  );
    
    function my_new_function( $ID, $post ) {
        ...
    }
    Ответ написан
    Комментировать