这是我第一页上的表格。我必须管理,如果用户没有登录,在这种情况下,提交表单后的行动是登录页面。
<?php/** Template Name: Form */
get_header(); ?>
<form id="new_post" <?php do_action(\'post_edit_form_tag\'); ?> name="new_post" method="post" action="<?php if ( is_user_logged_in() ) { } else { echo \'http://localhost/manage/login\'; } ?>">
<p><label for="title">Project Title</label><br />
<input type="text" id="title" value="" name="title" /></p>
<p><label for="Category">Category:</label><br />
<?php wp_dropdown_categories(\'type=post&show_count=0&selected=-1&hierarchical=1&depth=1&hide_empty=0&exclude=0&show_option_none=Select Category&taxonomy=category\');?></p>
<p><label for="description">Project Description</label><br/>
<textarea id="description" name="description" ></textarea></p>
<p><label for="post_date">submit date:</label></br>
<input type="text" value="" tabindex="5" size="16" name="post_date" id="post_date" /></p>
<p align="right"><input type="submit" value="Publish" tabindex="6" id="submit" name="submit" /></p>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( \'new-post\' ); ?></form>
<?php get_footer(); ?>
提交此表单后,我将在登录页面上发送帖子值,在用户登录后,我想用UserID保存帖子。此页面代码:
<?php
/**
* * Template Name: Login Page
*/
get_header(); ?>
<?Php
// Values Comin From 1st Page
$title = $_POST[\'title\'];
$description = $_POST[\'description\'];
$category = $_POST[\'cat\'];
$date = $_POST[\'post_date\'];
if (isset ($_POST[\'login\'])) {
$new_post = array(
\'post_author\' => LOGGED IN USERID,
\'post_title\' => $title,
\'post_content\' => $description,
\'post_status\' => \'publish\',
\'post_type\' => \'post\'
);
//save the new post
$pid = wp_insert_post($new_post);
add_post_meta( $pid, \'category\', $category , true );
add_post_meta( $pid, \'date\', $date, true );
}
?>
<form id="login" action="login" method="post" name="new_post">
<h1>Site Login</h1>
<p class="status"></p>
<label for="username">Username</label>
<input id="username" type="text" name="username">
<label for="password">Password</label>
<input id="password" type="password" name="password">
<input class="submit_button" type="submit" value="Login" name="login">
<?php wp_nonce_field( \'ajax-login-nonce\', \'security\' ); ?>
<input type="hidden" name="action" value="new_post" />
<?php wp_nonce_field( \'new-post\' ); ?>
</form>
<?php get_footer(); ?>
这就是我正在使用的代码。