Title: wp_insert_post permalink issue
Last modified: November 10, 2020

---

# wp_insert_post permalink issue

 *  Resolved [badamadam](https://wordpress.org/support/users/badamadam/)
 * (@badamadam)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp_insert_post-permalink-issue/)
 * Hi, firstly thanks for such a fantastic plugin.
 * I am currently programmatically creating a post using wp_insert_post, however,
   I am finding that the permalink is not updated to my correct “permastructure”.
 *     ```
       $post_id = wp_insert_post(array(
                   'post_type' => 'artist-page',
                   'post_title' => $post_title,
                   'post_status' => 'publish',
                   'comment_status' => 'closed',   // if you prefer
                   'ping_status' => 'closed',      // if you prefer
               ));
       ```
   
 * I have noticed that the function **new_post_uri()** found within **permalink-
   manager-uri-functions-post.php** is stopping the correct URL from being executed
   in the loop, specifically line **745**
 * `if(in_array($post_object->post_status, array('auto-draft', 'trash')) || empty(
   $post->post_title) || (!empty($post_object->post_name) && $post_object->post_name
   == 'auto-draft')) { return $post_id; }`
 * Notice **!empty($post->post_title)** rather than **!empty($post_object->post_title)**
   once this is changed, the uri’s run perfectly with my new inserted post.
 * For whatever reason my global **$post** is empty, I believe this is most likely
   the cause, however the code $post->post_title should most likely be changed to**
   $post_object->post_title **to be consistent with the rest of the if statement.
 * Thanks again,
    -  This topic was modified 5 years, 4 months ago by [badamadam](https://wordpress.org/support/users/badamadam/).

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

 *  Plugin Author [Maciej Bis](https://wordpress.org/support/users/mbis/)
 * (@mbis)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp_insert_post-permalink-issue/#post-13648250)
 * Hi [@badamadam](https://wordpress.org/support/users/badamadam/),
 * you are absolutely right – thank you for letting me know. That is my obvious 
   mistake.
 * As you suggested, I will change the contents of permalink-manager-uri-functions-
   post.php (line 745) from:
    `if(in_array($post_object->post_status, array('auto-
   draft', 'trash')) || empty($post->post_title) || (!empty($post_object->post_name)&&
   $post_object->post_name == 'auto-draft')) { return $post_id; }`
 * to:
    `if(in_array($post_object->post_status, array('auto-draft', 'trash')) ||
   empty($post_object->post_title) || (!empty($post_object->post_name) && $post_object-
   >post_name == 'auto-draft')) { return $post_id; }`
 * The hotfix will be included in the next version of plugin.
 * Best regards,
    Maciej
 *  Thread Starter [badamadam](https://wordpress.org/support/users/badamadam/)
 * (@badamadam)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp_insert_post-permalink-issue/#post-13653227)
 * [@mbis](https://wordpress.org/support/users/mbis/) thanks – that is great news,
   appreciated for your responsiveness and the quick turnaround.
 * Kind regards
    Adam
 *  [emangham](https://wordpress.org/support/users/emangham/)
 * (@emangham)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp_insert_post-permalink-issue/#post-13726912)
 * Hey [@mbis](https://wordpress.org/support/users/mbis/), please can you include
   this in a release? It’s still stopping the correct URL from being executed in
   the loop on line 745, which is causing issues. Thank you!
 *  Plugin Author [Maciej Bis](https://wordpress.org/support/users/mbis/)
 * (@mbis)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp_insert_post-permalink-issue/#post-13726930)
 * Hi [@emangham](https://wordpress.org/support/users/emangham/),
 * I have just published a patch for 2.2.9.2 version:
    [https://plugins.trac.wordpress.org/changeset/2428815](https://plugins.trac.wordpress.org/changeset/2428815)
 * Please note that you will need to install to plugin again.
 * I apologize for all the inconvenience!
 * Best regards,
    Maciej
 *  [emangham](https://wordpress.org/support/users/emangham/)
 * (@emangham)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/wp_insert_post-permalink-issue/#post-13727001)
 * [@mbis](https://wordpress.org/support/users/mbis/), you legend – thank you!
 * Best,
    Elliott

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

The topic ‘wp_insert_post permalink issue’ is closed to new replies.

 * ![](https://ps.w.org/permalink-manager/assets/icon.svg?rev=2625166)
 * [Permalink Manager Lite](https://wordpress.org/plugins/permalink-manager/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/permalink-manager/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/permalink-manager/)
 * [Active Topics](https://wordpress.org/support/plugin/permalink-manager/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/permalink-manager/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/permalink-manager/reviews/)

 * 5 replies
 * 3 participants
 * Last reply from: [emangham](https://wordpress.org/support/users/emangham/)
 * Last activity: [5 years, 4 months ago](https://wordpress.org/support/topic/wp_insert_post-permalink-issue/#post-13727001)
 * Status: resolved