我们如何在前端WordPress的自定义帖子类型中添加功能图像。任何人都可以帮忙吗?我尝试过,但没有得到正确的结果。请帮忙。
<?php
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
global $wpdb;
if ( trim( $_POST['postTitle'] ) === '' ) {
$postTitleError = 'Please enter a title.';
$hasError = true;
}
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'stories',
'post_status' => 'publish'
);
echo $post_id = wp_insert_post( $post_information );
if ($_FILES) {
array_reverse($_FILES);
$i = 0;//this will count the posts
foreach ($_FILES as $file => $array) {
if ($i == 0) $set_feature = 1; //if $i ==0 then we are dealing with the first post
else $set_feature = 0; //if $i!=0 we are not dealing with the first post
$newupload = insert_attachment($file,$pid, $set_feature);
echo $i++; //count posts
}
}
}
?>
<div class="mid-wrapper">
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<label for="postTitle"><?php _e('Post Title:', 'framework') ?></label>
<input type="text" name="postTitle" id="postTitle" class="required" />
</fieldset>
<fieldset>
<label for="postContent"><?php _e('Post Content:', 'framework') ?></label>
<textarea name="postContent" id="postContent" rows="8" cols="30" class="required"></textarea>
</fieldset>
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<fieldset>
<input type="hidden" name="submitted" id="submitted" value="true" />
<?php wp_nonce_field( 'post_nonce', 'post_nonce_field' ); ?>
<button type="submit" name="submitted"><?php _e('Add Post', 'framework') ?></button>
</fieldset>
</form>
</div>
我们如何在前端WordPress的自定义帖子类型中添加功能图像。任何人都可以帮忙吗?我尝试过,但没有得到正确的结果。请帮忙。