开发者

Wordpress wp_insert_post () redirect?

Now i create a wordpress front-end post, after wp_insert_post(); i want to redirect into the full page of that post data. Here i use the this way, so it was redirect the blog index page, but i need this page redirect this post full page.

      $post_insert = array(
        'post_title'    => $title,
开发者_如何学JAVA        'post_content'  => $content,
        'tags_input'    => $post_tags,
        'post_status'   => 'publish',
      );
      $post_id = wp_insert_post( $post_insert );
      wp_redirect( site_url()."?post=$post_id" );
      exit();


I think the issue is with $post_id being inside the double quotes. Try this instead:

wp_redirect( site_url()."?post=".$post_id);


It is better to use this:

wp_redirect(get_permalink($post_id));

The get_permalink method is the Wordpress built-in method to get a permanent link. See this url for the documentation for this method: http://codex.wordpress.org/Function_Reference/get_permalink

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜