为用户提交的Wordpress帖子添加图像附件功能

时间:2012-12-03 22:01:22

标签: image forms wordpress submit

我想添加用户将图像附加到他们提交给wordpress帖子的表单的功能。任何人都这样做或知道如何?

class submit_custom_forms{ 

public function __construct() {

}

public function processForms(){
   extract($_POST);

  $postData = array(
   'post_title' => wp_strip_all_tags( $full_name ),
   'post_status' => 'pending',
   'post_type' => 'story', /*the custom post type*/
   'post_author' => 1,
   'post_category' => array($catID)); 

      $pid = wp_insert_post( $postData );

   //Process Custom Fields
      if(!empty($pid) && is_numeric($pid) && !empty($custom)){
          foreach($custom as $key => $value){
           if(!empty($value) && !is_array($value)){
             add_post_meta($pid, $key, $value);
            } elseif(!empty($value) && is_array($value)){
               foreach($value as $k => $v){
                  add_post_meta($pid, $key, $v, false);
           }
          }

        }
       } 

      $success = "Thank you for submitting.";
      return (!empty($pid) && is_numeric($pid)) ? array('success' => "$success $imageUplodMsg $msgVid") : array('error' => 'An error occured. Please try again.');
}

}

1 个答案:

答案 0 :(得分:1)

此链接有用: wp_insert_attachment