Title: Add/Remove redirects programmatically
Last modified: August 31, 2023

---

# Add/Remove redirects programmatically

 *  Resolved [topi_r](https://wordpress.org/support/users/topi_r/)
 * (@topi_r)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/add-remove-redirects-programmatically/)
 * I have Persons CPT. All persons are handled via integration. Persons come and
   go and this leads to 404 problems.
 * `//Set absent persons to draft
   $args = array('posts_per_page' => -**1, 'post_status'
   => 'any', 'post_type' => 'person',);$persons = get_posts($args);foreach ($persons
   as $person) {if (!in_array($person->ID, $persons_in_API)) {wp_update_post(['ID'
   => $person->ID, 'post_status' => 'draft', ]); }}
 * I would like to create redirection after wp_update_post(). How can I achieve 
   this?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [John Godley](https://wordpress.org/support/users/johnny5/)
 * (@johnny5)
 * [2 years, 9 months ago](https://wordpress.org/support/topic/add-remove-redirects-programmatically/#post-17014553)
 * All details can be found here:
 * [https://redirection.me/developer/](https://redirection.me/developer/)
 *  [JochenT](https://wordpress.org/support/users/jochent/)
 * (@jochent)
 * [2 years, 8 months ago](https://wordpress.org/support/topic/add-remove-redirects-programmatically/#post-17054791)
 * Hi topi_r, 
   I’ve created a gist with a class which allows to add/remove redirects
   programmatically. It is not an easy one liner.
 * [class-redirection-redirects.php](https://gist.github.com/jotazzu/e9571973ad91877eb9e77839ca9e29c0)

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Add/Remove redirects programmatically’ is closed to new replies.

 * ![](https://ps.w.org/redirection/assets/icon-256x256.jpg?rev=983639)
 * [Redirection](https://wordpress.org/plugins/redirection/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/redirection/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/redirection/)
 * [Active Topics](https://wordpress.org/support/plugin/redirection/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/redirection/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/redirection/reviews/)

 * 2 replies
 * 3 participants
 * Last reply from: [JochenT](https://wordpress.org/support/users/jochent/)
 * Last activity: [2 years, 8 months ago](https://wordpress.org/support/topic/add-remove-redirects-programmatically/#post-17054791)
 * Status: resolved