如何为前端发布实施“从现有标签中选择”?

时间:2016-04-04 12:45:36

标签: php html forms tags

Hy,在标签的底部:我想添加一些东西,以便能够从现有标签中进行选择。

用户可以创建新标签,但我希望他们能够从现有标签中进行选择。

这是我从WP Core中提取的,我有没有机会使用这些代码? http://textuploader.com/5w9pf

这是我想要的图像: enter image description here

这是html和php代码:

case "window-image":
            $format = 'image';
            $title = esc_html($_POST['title_image']);
            $tags = $_POST['tags_image'];
            $comments = isset($_POST['comments_image']) ? 1 : 0;
            $user_id = $id;

            if(($_FILES['file']['error'] != 0) || $title == '' || str_word_count($tags) < 3) {
                wp_redirect(home_url('/') . '?posterror=1');
            exit; 
            }         

            $post = array(
              'comment_status' => $comment_status,
              'ping_status'    => 'open',
              'post_author'    => $user_id,
              'post_content'   => '',
              'post_status'    => $status,
              'post_title'     => $title,
              'post_type'      => 'post',
             );  
            $post_id = wp_insert_post($post);

    #Upload and Create attachment
        if (!function_exists('wp_generate_attachment_metadata')){
            require_once(ABSPATH . "wp-admin" . '/includes/image.php');
            require_once(ABSPATH . "wp-admin" . '/includes/file.php');
            require_once(ABSPATH . "wp-admin" . '/includes/media.php');
        }
            $upload = wp_upload_bits( $_FILES['file']['name'], null, file_get_contents( $_FILES['file']['tmp_name'] ) );
            $wp_filetype = wp_check_filetype( basename( $upload['file'] ), null );
            $check = getimagesize($_FILES["file"]["tmp_name"]);
            if($check !== false) {
            $uploadOk = 1;
                } else {
                echo "File is not an image.";
            $uploadOk = 0;
                wp_trash_post( $post_id  );
            }

            $wp_upload_dir = wp_upload_dir();
            $attachment = array(
                'guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path( $upload['file'] ),
                'post_mime_type' => $wp_filetype['type'],
                'post_title' => preg_replace('/\.[^.]+$/', '', basename( $upload['file'] )),    
                'post_content' => '',
                'post_author' => $user_id,
                'post_status' => 'inherit'
            );
            $attach_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
            require_once(ABSPATH . 'wp-admin/includes/image.php');
            $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] );
            wp_update_attachment_metadata( $attach_id, $attach_data );
    #Upload and Create attachment

    #Use attachment
            update_post_meta( $post_id, '_thumbnail_id', $attach_id );
    #Use attachment
            break;

--- HTML ----

    <div class="post-window window-image">
    <div class="window-left">
    <textarea name="title_image" class="form-control" rows="1" placeholder="<?php _e('Post title', 'Aruna');?>"></textarea>                         
    Memes and GIFs -- Max size: 10MB
    <input type="file" class="upload" name="file" accept="image/*"/>
    <hr>
    <center><button type="button" class="btn btn-danger" data-toggle="collapse" data-target="#Info-ImagePost">Please read before posting</button></center>
    <div id="Info-ImagePost" class="collapse">
    <div class="alert alert-info">          
    <em><p>If you dont know how to post please take a look at FAQ page: <a href="http://www.9tanks.com/faq/"><button type="button" class="btn btn-success btn-xs">FAQ</button></a></p></em>
    <em><p>If your post doesnt show or has a problem please report the post and in the shortest time we will resolve or you can delete your own post and try again</p></em>
    </div>
    </div>
    </div>
    <aside>
<div class="outer">
    <div class="inner"> 
<div class="tags-wrap">
    <h3><?php _e('Tags', 'Aruna');?>:</h3>
    <p><?php _e('Please write at least 3 tags. Ex: IS-4,El Halluf,Failshot');?></p>
    <input name="tags_image" class="tags-selector" value="" />
</div>
</aside>
</div>

0 个答案:

没有答案