WordPress.org

Forums

Quick Page/Post Redirect Plugin
[resolved] Use redirect in wp_insert_post function (2 posts)

  1. syntaxlb
    Member
    Posted 2 years ago #

    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/

  2. prophecy2040
    Member
    Plugin Author

    Posted 2 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Quick Page/Post Redirect Plugin
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.