Wordpress表单自定义字段

时间:2012-03-13 16:12:24

标签: wordpress

我使用wordpress创建了一个表单,它返回标题和描述。我需要返回一些自定义字段。我搜索过互联网,发现很多答案并没有很好地解释它们并没有最终为我工作。表单将返回一个帖子,其中包含标题,说明,已填写的自定义字段。谢谢!

if('POST'== $ _SERVER ['REQUEST_METHOD']&&!empty($ _POST ['action'])&& $ _POST ['action'] ==“new_post”){

// Do some minor form validation to make sure there is content
if (isset ($_POST['title'])) {
    $title =  $_POST['title'];
} else {
    echo 'Please enter the wine name';
}
if (isset ($_POST['description'])) {
    $description = $_POST['description'];
} else {
    echo 'Please enter some notes';
}


// ADD THE FORM INPUT TO $new_post ARRAY
$new_post = array(
'post_title'    =>  $title,
'post_content'  =>  $description,
'post_Blog_URL' => $URL,  
'post_status'   =>  'publish',           // Choose: publish, preview, future, draft, etc.
'post_type' =>  'post'  //'post',page' or use a custom post type if you want to
);

add_post_meta($post_id, $meta_key, 'URL' , $unique); 

//SAVE THE POST
$pid = wp_insert_post($new_post);

//REDIRECT TO THE NEW POST ON SAVE
$link = get_permalink( $pid );
wp_redirect( $link );

} //结束开始整个表格的声明

do_action('wp_insert_post','wp_insert_post');

提交您自己的!

                <div id="postbox">

                <form id="new_post" name="new_post" method="post" action="" class="" enctype="multipart/form-data">

                <!-- post name -->
                <fieldset name="name">
                    <label>Name of the Article</label>
                    <input type="text" id="title" value="" tabindex="1" size="20" name="title" />
                </fieldset>   


                <!-- post Content -->
                <fieldset class="content">
                    <label for="description">Description</label>
                    <textarea id="description" tabindex="15" name="description"></textarea>
                </fieldset>


                <button type="submit">Submit</button>

                <input type="hidden" name="action" value="new_post" />

                <?php wp_nonce_field( 'new-post' ); ?>

                </form>

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您希望能够在表单中显示Post Meta Fields。

有一些功能可以设置,更新和检索这些功能,这将有所帮助:

get_post_metaget_post_custom

add_post_meta

update_post_meta

使用这些功能,您可以为帖子创建任何类型的元信息,并在管理面板或最终用户中显示它们,具体取决于方案。