Title: Use redirect in wp_insert_post function
Last modified: August 20, 2016

---

# Use redirect in wp_insert_post function

 *  Resolved [syntaxlb](https://wordpress.org/support/users/syntaxlb/)
 * (@syntaxlb)
 * [13 years, 4 months ago](https://wordpress.org/support/topic/use-redirect-in-wp_insert_post-function/)
 * Hi,
 * I insert WordPress Post in PHP with wp_insert_post() function. How i can use 
   this plugin for add a redirect in PHP ?
 * Good day,
    Syntaxlb
 * [http://wordpress.org/extend/plugins/quick-pagepost-redirect-plugin/](http://wordpress.org/extend/plugins/quick-pagepost-redirect-plugin/)

Viewing 1 replies (of 1 total)

 *  [Don Fischer](https://wordpress.org/support/users/prophecy2040/)
 * (@prophecy2040)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/use-redirect-in-wp_insert_post-function/#post-3365488)
 * syntaxlb,
    You can add a redirect by adding meta data to the post after you insert
   it. You need to assign a variable to your wp_insert_post call, and then you can
   add the meta, like so:
 *     ```
       //do your insert like normal
       $the_new_post = wp_insert_post($your_post_args);
       //then check it and add meta data
       if($the_new_post !== false){
         add_post_meta($the_new_post, '_pprredirect_active', '1', true);
         add_post_meta($the_new_post, '_pprredirect_url', 'http://redirect.url/here/', true);
         add_post_meta($the_new_post, '_pprredirect_type', '301', true);
       }
       ```
   
 * Other meta items available are:
    `_pprredirect_newwindow` where the value can
   be 1 or 0 `_pprredirect_relnofollow` where the value can be 1 or 0 `_pprredirect_rewritelink`
   where the value can be 1 or 0
 * The `_pprredirect_type` can be `301`, `302`, `307` or `meta`.
 * Hope this helps.
    Regards, Don

Viewing 1 replies (of 1 total)

The topic ‘Use redirect in wp_insert_post function’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/quick-pagepost-redirect-plugin_8d7b6f.
   svg)
 * [Quick Page/Post Redirect Plugin](https://wordpress.org/plugins/quick-pagepost-redirect-plugin/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/quick-pagepost-redirect-plugin/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/)
 * [Active Topics](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/quick-pagepost-redirect-plugin/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Don Fischer](https://wordpress.org/support/users/prophecy2040/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/use-redirect-in-wp_insert_post-function/#post-3365488)
 * Status: resolved