WP在执行函数后插入POST重定向

时间:2011-02-08 作者:Robin I Knight

使用函数提交自定义字段后,标准重定向不再工作。我们希望的是,在插入帖子以重定向用户后,标准的wp\\U重定向目前不起作用。我推测这是因为自定义字段提交功能。

代码

if ( is_user_logged_in() ) {
$my_post = array(
    \'post_title\' => $_SESSION[\'booking-form-title\'],
    \'post_date\' => $_SESSION[\'cal_startdate\'],
    \'post_content\' => \'This is my post.\',
    \'post_status\' => \'publish\',
    \'post_type\' => \'booking\',
    \'post_author\' => $user_ID,
);
 $the_post_id = wp_insert_post( $my_post );

__update_post_meta( $the_post_id, \'duration\', $_SESSION[\'booking-form-actual-duration\'] );
__update_post_meta( $the_post_id, \'picture\', $_SESSION[\'booking-form-picture\'] );
__update_post_meta( $the_post_id, \'totalprice\', $_SESSION[\'booking-form-total-price\'] );
__update_post_meta( $the_post_id, \'activityduration\', $_SESSION[\'booking-form-total-duration\'] );
__update_post_meta( $the_post_id, \'totaldives\', $_SESSION[\'booking-form-total-dives\'] );

query_posts(\'post_type=services\'); while (have_posts()) : the_post();
__update_post_meta( $the_post_id, \'producttitle\'.get_the_ID(), $_SESSION[\'products-form-title\'.get_the_ID()]); 
__update_post_meta( $the_post_id, \'productprice\'.get_the_ID(), $_SESSION[\'products-form-price\'.get_the_ID()]); 
__update_post_meta( $the_post_id, \'productduration\'.get_the_ID(), $_SESSION[\'products-form-duration\'.get_the_ID()]);
__update_post_meta( $the_post_id, \'productdives\'.get_the_ID(), $_SESSION[\'products-form-dives\'.get_the_ID()]);  
__update_post_meta( $the_post_id, \'productquantity\'.get_the_ID(), $_SESSION[\'products-form-quantity\'.get_the_ID()]); 

 endwhile; 
 $linkit = get_permalink($the_post_id);
wp_redirect($linkit);
}
else {;}
wp\\U重定向产生以下错误Warning: Cannot modify header information - headers already sent by (output started at /home/divethe1/public_html/update/wp-content/themes/master/type-booking.php:18) in /home/divethe1/public_html/update/wp-includes/pluggable.php on line 890

正因为如此,我们在同一页上将$the\\u post\\u id更改为$post\\u id否定了该函数,仍然不执行重定向。其功能和程序可在以下网址找到:WP insert post PHP function and Custom Fields

因此,目标是将用户重定向到由wp\\u insert\\u post创建的页面。如果有人能看到我错在哪里,非常感谢,

非凡的

1 个回复
SO网友:Rarst

您是否尝试输出链接并验证其是否正确?

你也应该打电话die(); 就在重定向之后。

结束

相关推荐

Subdomain redirect problem

Wordpress已安装到我的根目录(/根/)。我有一个子域名(dammani.techbrij.com),我想从子域名访问主域名的一些文件。我做了以下事情:include_once(\'/root/wp-config.php\'); include_once(\'/root/wp-load.php\'); include_once(\'/root/wp-includes/wp-db.php\'); 现在,“http://techbrij.com/dammani“工作正常,但是”