• I’m creating a plugin where one of the first things it does is create a page. I have it create the post object, set the post_type as page and other parameters and then I set the page_template to a template file in my plugin directory. However, it doesn’t seem like it’s picking up on it. Here’s a snippet of what I’m working with:

    $the_page = get_page_by_title( $the_page_title );
    
        if ( ! $the_page ) {
    
            // Create post object
            $_p = array();
            $_p['post_title'] = $the_page_title;
            $_p['post_content'] = "This text may be overridden by the plugin. You shouldn't edit it.";
            $_p['post_status'] = 'publish';
            $_p['post_type'] = 'page';
            $_p['comment_status'] = 'closed';
            $_p['ping_status'] = 'closed';
            $_p['post_category'] = array(1); // the default 'Uncategorised'
            $_p['page_template'] = '/template-our-locations.php';
    
            // Insert the post into the database
            $the_page_id = wp_insert_post( $_p );
    
        }

    Am I doing this properly?

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Setting page template for page created by plugin’ is closed to new replies.