$current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header('Location: '.$current_url);
Here the complete code
<?php
$postTitleError = '';
$postcontentError = '';
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
if (trim($_POST['postTitle']) === '' || $_POST['postContent'] === '' ) {
if(trim($_POST['postTitle']) === '') {
$postTitleError = 'Please enter a title.';
}
if(trim($_POST['postContent']) === '') {
$postcontentError = 'Please enter a title.';
}
}
else {
$post_information = array(
'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
'post_content' => esc_attr(strip_tags($_POST['postContent'])),
'post_status' => 'publish', // Choose: publish, preview, future, pending, draft, etc.
'post_type' => 'post'
);
$post_id = wp_insert_post($post_information);
?>
<?php
}
$current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header('Location: '.$current_url);
}
?>
<div class="col-xs-12">
<form action="" id="primaryPostForm" method="POST" enctype="multipart/form-data">
<div class="form-group">
<!--<label for="postTitle"><?php _e('Nome:', 'framework') ?></label>!-->
<input type="hidden" class="form-control" autocomplete="off" name="postTitle" id="postTitle" value="" placeholder="Nome:" required />
</div>
<?php if($postTitleError != '') { ?>
<span class="error"><?php echo $postTitleError; ?></span>
<div class="clearfix"></div>
<?php } ?>
<div class="form-group">
<!--<label for="postContent"><?php _e('Mensagem:', 'framework') ?></label>!-->
<textarea name="postContent" class="form-control" autocomplete="off" rows="4" placeholder="Mensagem..." ></textarea>
</div>
<?php if($postcontentError != '') { ?>
<span class="error"><?php echo $postcontentError; ?></span>
<div class="clearfix"></div>
<?php } ?>
<div class="form-group">
<?php wp_nonce_field('post_nonce', 'post_nonce_field'); ?>
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit" class="btn btn-primary btn-lg btn-block"><?php _e('Enviar', 'framework') ?></button>
</div>
</form>
</div>
]]>
ERROR
Warning: Cannot modify header information – headers already sent by (output started at
tranks
]]>It happened because anything echo or print before the header location call.
Currently i have modified the code please check it.
<?php
$postTitleError = '';
$postcontentError = '';
if ( isset( $_POST['submitted'] ) && isset( $_POST['post_nonce_field'] ) && wp_verify_nonce( $_POST['post_nonce_field'], 'post_nonce' ) ) {
if (trim($_POST['postTitle']) === '' || $_POST['postContent'] === '' ) {
if(trim($_POST['postTitle']) === '') {
$postTitleError = 'Please enter a title.';
}
if(trim($_POST['postContent']) === '') {
$postcontentError = 'Please enter a title.';
}
}
else {
$post_information = array(
'post_title' => esc_attr(strip_tags($_POST['postTitle'])),
'post_content' => esc_attr(strip_tags($_POST['postContent'])),
'post_status' => 'publish', // Choose: publish, preview, future, pending, draft, etc.
'post_type' => 'post'
);
$post_id = wp_insert_post($post_information);
?>
<?php
}
$current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
if(!headers_sent())
{
header('Location: '.$current_url);
exit;
}
else
{
?>
<script language="javascript">
window.location.href = "<?PHP echo $current_url;?>";
</script>
<?php
}
}
?>
Regards
Sumith