Support » Plugins » Hacks » Front end posting, not working wp_redirect with 'cannot modify header informatio

  • Im trying to make front end posting page but, sometime ‘wp_redirect’ is not working with ‘cannot modify header information’ error. adding data is working well but I don’t know why is working well without error sometime, showing error sometime..

    if (isset ($_POST['post_title'])) {
        $title =  $_POST['post_title'];
    } else {
        echo 'Please enter a game  title';
    if (isset ($_POST['description'])) {
        $description = $_POST['description'];
    } else {
        echo 'Please enter the content';
    $new_post = array(
        'post_title'    => $title,
        'post_content'  => $description,
        'post_status'   => 'publish',
        'post_type' => 'property',
        'tax_input' => array( 'property_type' => array($property_type), 'suburbs' => array($suburbs) )
    //save the new post and return its ID
    $pid = wp_insert_post($new_post); 
       //add thumbnail
        if (!function_exists('wp_generate_attachment_metadata')){
                require_once(ABSPATH . "wp-admin" . '/includes/image.php');
                require_once(ABSPATH . "wp-admin" . '/includes/file.php');
                require_once(ABSPATH . "wp-admin" . '/includes/media.php');
             if ($_FILES) {
                foreach ($_FILES as $file => $array) {
                    if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
                        return "upload error : " . $_FILES[$file]['error'];
                    $attach_id = media_handle_upload( $file, $pid );
            if ($attach_id > 0){
                //and if you want to set that image as Post  then use:
            }  //add thumbnail end
    update_post_meta($new_post_id, 'tax_input', $property_type);
    update_post_meta($new_post_id, 'tax_input', $suburbs);
    //insert custom fields
    $url = get_permalink( $pid );

    Sorry for my bad english, please help me out… and I’m not a programmer just understand some codes anyway…

    Many thanks!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • even I removed
    $url = get_permalink( $pid ); wp_redirect($url); exit();
    it’s not working as well….

    Moderator bcworkz


    wp_redirect() works by sending out a PHP header() command to the browser. The header() command fails with that error if any regular HTML content has already been sent to the browser in response to a request.

    It appears the problem is the echo statements near the beginning. If both fields are provided, the echo statements do not output text and the redirect will work. If either or both fields are missing, a text message is sent before the redirect, so the redirect fails.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Front end posting, not working wp_redirect with 'cannot modify header informatio’ is closed to new replies.