0

I'm trying to set my template to the Elementor Canvas when using wp_insert_post but it isn't working. It is creating the new page fine but not using the canvas. What am I doing wrong?

{
"action": "create_post",
"post_author": "<authorID>",
"post_content": "<post content>",
"post_title": "Leave us a Review",
"post_status": "publish",
"post_type": "page",
"comment_status": "closed",
"post_name": "<post-name>",
"page_template": "elementor_canvas"

}

1 Answer 1

1

You can check this code I am able to work with this

function cutom_function() {

    $new_page_id = wp_insert_post( array(
        'post_title'     => 'PKB',
        'post_type'      => 'page',
        'post_name'      => 'pkb',
        'comment_status' => 'closed',
        'ping_status'    => 'closed',
        'post_content'   => '',
        'post_status'    => 'publish',
        'post_author'    => get_user_by( 'id', 1 )->user_id,
        'menu_order'     => 0,
        // Assign page template
        'page_template'  => 'pratik.php'
    ) );
1
  • Thanks, that code looks quite similar to mine, can you see any difference in mine that would cause the template to not set? My template name is definitely correct.
    – Mitch C
    Apr 27 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.