Advertisement
bedas

CRED Example

Apr 17th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.79 KB | None | 0 0
  1. add_action('cred_save_data', 'my_save_data_action',10,2);
  2. function my_save_data_action( $post_id, $form_data ) {
  3.    
  4.     // if a specific form
  5.     if ( $form_data['id'] == 95 ) {
  6.  
  7.         $book_content = get_post( $post_id );
  8.         $summary = get_post_meta( $post_id, 'wpcf-summary', true );
  9.         $authors = get_the_terms( $post_id, 'book-authors' );
  10.  
  11.         //get authors
  12.         $auth = array();
  13.         foreach( $authors as $author ) {
  14.             $auth[] = $author->name;
  15.         }
  16.  
  17.         //insert the post
  18.         wp_insert_post( array(
  19.             'post_title' => sprintf( 'New book is now available: %s', $book_content->post_title ),
  20.             'post_status' => 'publish',
  21.             'post_content' => sprintf( 'A new book has been added, %s by %s. <br /><br /><strong>Summary:</strong> %s', $book_content->post_title, join(', ', $auth ), $summary )
  22.         ) );
  23.  
  24.     }
  25.  
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement