I searched everywhere for this but couldn't find any help. I'm working on a plugin that generates posts from a database, like so:

foreach ( $items as $item ) {
    $content = $core->parseTpl($item->Asin, $this->content);
    $titleColumn = $this->titleColumn;
    $postarr     = array(
        'post_content' => $content,
        'post_title'   => $item->$titleColumn,
        'post_status'  => 'draft',

    $postId = wp_insert_post( $postarr );

    //more code...

When I do this, the generated permalinks look something like this:


However, I want the permalinks to look like specified in the WP-backend:

enter image description here

Using the wp_insert_post function doesn't seem to apply the permalink formatting. What do I have to do, so that my created posts have the formatted permalinks?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.