Wordpress wp_insert_post () redirect?

2019-08-26 23:31发布

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,
        '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();

标签: wordpress
2条回答
Summer. ? 凉城
2楼-- · 2019-08-27 00:27

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

wp_redirect( site_url()."?post=".$post_id);
查看更多
孤傲高冷的网名
3楼-- · 2019-08-27 00:32

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

查看更多
登录 后发表回答