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,
- The topic ‘wp_insert_post permalink issue’ is closed to new replies.