If you look at the documentation, you can insert title, content, slug, etc. using wp_insert_post
then use update_post_meta
to assign the template to that post.
You can write like this
$post_arr = array(
'post_title'=>'My title goes here',
'post_content'=>'This is my long content.',
'post_excerpt' => 'My Excerpt',
'post_status' => 'publish',
);
$new_post_id = wp_insert_post($post_arr);
Then set template like this.
update_post_meta( $new_post_id, '_wp_page_template', 'template-file.php' );
To see more options for wp_insert_post
, you can check it’s documentation page.
Related Posts:
- Get page content using slug
- Change the_title() of a page dynamically
- Pages 404 in wordpress
- How to create a dynamic page based on form data with a plugin?
- Use an empty page to build custom plugin output
- Is it possible for a plugin to register a page template file?
- Dropdown list of pages to get page id to store in plugin options
- Calling a function from functions.php in custom page/ blog post
- How do I approach removing menu items on the fly based on settings in my plugin?
- Set a specific page as 404 – not found via my own plugin
- Create a Page via plugin
- Secure Pages Best Practice
- Plugin generated virtual pages
- Add Password Generator on password protected page
- ECHO Executing 4 Times In Head
- WordPress pages are not published due to External database connection with WPDB class
- Create page (not the post type) dynamically
- Multiple array for post_content on plugin activation
- How to list all images used on a specific page?
- Create fixed static pages
- Set page to draft on plugin deactivation
- How to create archive page to add in menu
- Load specific page when a custom URL is hit
- Plugin frontend page design irrespective of the theme used
- Custom non-template page on front end fails to render
- How do I control the list of Pages an author can see?
- How to add conent (text) to Add New pages form of admin in WordPress
- auto create only 1 wp page in activate custom plugin
- Create pages for authors
- How do I use (or mimic) document.getElementById() on a page loaded from WordPress database?
- Using a Page Template Not in Theme
- Generating Multiple Divi Pages from Database
- Problem with Owl Carousel, infinite loop [closed]
- Add screen options to custom admin pages
- Completely remove WP_Admin_Bar for specific user roles
- WordPress and PHP Sessions – Security and Performance
- WordPress Hook for user register
- how to use thickbox in admin?
- Nonce in settings API with tabbed navigation
- How does WordPress treat rewrite rules “under the hood”?
- Add rewrite rule in plugin: with .htaccess in plugin folder or using WordPress functions
- Plugin vs Settings load order (woocommerce dependency)
- Screenshot are not showing up on plugin page
- How to not let a user with a new role edit users that have administrator role?
- async code or cron job?
- Configuring WordPress Auth Cookie Expiration
- How to display a message about updates in the plugin list
- Loading jQuery and jQuery plugin script files correctly [duplicate]
- WordPress not working on localhost
- manage_posts_custom_column, showing serial number using increment in loop
- Custom delete option button in plugin settings
- SQL query for custom taxonomy slugs
- Sub Menu content is being duplicated
- how to append custom metabox field with the ACF custom fields id in wordpress development
- $_FILES empty on created_{taxonomy} and create_{taxonomy} yet is is not on edit_{taxonomy}
- What should happen when a WordPress Plugin is activated across the network (Network Wide Activation)
- Storing data in wordpress database from ajax call from different website
- Prevent invalid or empty values from being saved to the database and retain the form field values upon error
- Hide shortcodes “code” when using the “editor” the same as wordpress do with “gallery”
- Adding fields to category manager. Does a method exist to get the link to the category edit screen?
- How to test a WordPress plugin in real time
- How to Trigger WP CRON at Local Timestamp?
- Force download file from plugin (change output http headers)
- Distributing Frontend Assets with Plugins
- How to get all product in the woo-commerce? [closed]
- Wp-admin Custom User Management
- Check user’s role and store in variable
- Hook add_attachment error
- Undefined variable’s error when expected to have passed the content of variable [closed]
- Shortcode conflicts
- How can I add rewrite rules to a class-based plugin?
- hook update_option/updated_option empty $old_value and $value
- Issues Updating Post Meta with AJAX (Seems simple but cannot figure it out)
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- Sharing Variables between scheduled events
- Issue with plugin sub menu and pages
- How can I programmatically change a MySql variable (foreign_keys_check)?
- Problem with display data from get_option
- Screenshots on plugin page taken old [closed]
- Get Posts by IDs (optionally)
- How do I duplicate a single post, with all its properties, and save it as a different post?
- Why doesn’t my Table get created?
- Extract Information from post content (using regex?)
- want to show CMB2 metabox on woocommerce product data tab
- Can someone explain what’s the use of parse request function in WordPress?
- Add parameters to 3rd party callback function
- How does update method in Widget class saves $instance array from Select tag?
- WooCommerce – Stop assigning order numbers
- How can I pass WP_Query results to a plugin?
- Hiding the WordPress login and password fields from login page
- WordPress how do I echo SUM from a column of a MySQL table by user id AND type_operation
- Buddypress: adding a new tab direct user to their author page
- WC_Geolocation not found inside plugin
- Set widget icon in Customizer?
- How to customize the size of Featured Images or Post Thumbnails in WordPress?
- Why does unzip_file always return true but nothing happens?
- What happens when you create/edit a menu
- Add_menu_page and saving settings
- Updating Style From WP Options Setting Page
- Plugin – Proper way to handle 404 pages?