Support » Plugin: Permalink Manager Lite » wp_insert_post permalink issue

  • Resolved badamadam

    (@badamadam)


    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 1 year ago by badamadam.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Maciej Bis

    (@mbis)

    Hi @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

    (@badamadam)

    @mbis thanks – that is great news, appreciated for your responsiveness and the quick turnaround.

    Kind regards
    Adam

    emangham

    (@emangham)

    Hey @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

    (@mbis)

    Hi @emangham,

    I have just published a patch for 2.2.9.2 version:
    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

    (@emangham)

    @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.