Advertisement
Guest User

cptr_save

a guest
Jun 3rd, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. function cptr_save() { 
  2.     global $post_ID;
  3.  
  4.     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return;
  5.     if (!isset($_POST['myplugin_noncename'])) return;
  6.     if (!wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__))) return;
  7.     if (!current_user_can( 'edit_post', $post_ID ) ) return;
  8.  
  9.     $id = $_POST['post_ID'];
  10.     $related = isset($_POST['reladded']) ? $_POST['reladded'] : array();
  11.     update_post_meta($id, CI_CPTR_POST_RELATED, $related);
  12.    
  13.  
  14.    
  15.     // this is where I attempt to update the post_type
  16.  
  17.     $related_meta = get_post_meta($id, CI_CPTR_POST_RELATED, true);
  18.     $related_posts = array();
  19.     if (!empty($related_meta)) {
  20.         //Get a list of post IDs
  21.         foreach ($related_meta as $myrelated) {
  22.             $post = get_post($myrelated);
  23.             $related_posts[] = $post;
  24.         }
  25.        
  26.         if(count($related_posts)>0)
  27.         {
  28.             foreach ($related_posts as $post)
  29.             {
  30.             // Update post
  31.              $my_post = array( 'id' => $post->ID, 'post_status' => 'publish');
  32.             // Update the post into the database
  33.               wp_update_post( $my_post );
  34.                
  35.             }
  36.         }
  37.        
  38.     }
  39.    
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement