【发布时间】:2018-03-22 08:05:59
【问题描述】:
我有一个表格,任何人都可以通过我的 wordpress 网站上的链接访问。 当用户提交新帖子时,我希望他被重定向到他们刚刚创建的帖子。
这是表格:
<?php
wp_register_script( 'validation', 'http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js', array( 'jquery' ) );
wp_enqueue_script( 'validation' );
$post_information = array(
'post_title' => wp_strip_all_tags( $_POST['postTitle'] ),
'post_content' => $_POST['postContent'],
'post_type' => 'post',
'post_status' => 'publish'
);
wp_insert_post( $post_information );
$post_id = wp_insert_post( $post_information );
?>
<form action="" id="primaryPostForm" method="POST" onsubmit="return getContent()">
<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>
<fieldset>
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit"><?php _e('Add Post', 'framework') ?></button>
<?php wp_nonce_field( 'new-post' ); ?>
</fieldset>
</form>
我想通过添加这个
wp_redirect( get_permalink( $post_id ) );
die();
到 PHP 代码的末尾,它会将用户重定向到他们创建的帖子...我尝试了不同的方法,但它不起作用。它不会重定向到任何地方。 你有什么想法?我怎样才能做到这一点?谢谢!
【问题讨论】:
标签: php wordpress forms redirect