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'
) );
Related Posts:
- Creating a post with the REST API, curl and oauth returning 401 error
- Does the REST API (official) support custom post types?
- How to show single category archive
- Woocommerce api: create product with images – bad request
- Building a REST API for your web app exposes primary keys of DB records?
- Is it possible to create new user from external form using REST API?
- How to clone all WordPress Rest API end points
- Integrate admin plugin into template. Very interesant (live search + autocomplete with wp rest api, in vanilla js)
- Require()/Include() post template adding extra content
- How do i post data to url with fields?
- Adding Microsoft Teams Incoming Webhook to WordPress, Problem with Rest Route?
- REST API Plugin Update call back not updating the plugin
- Displaying a WooCommerce product via PHP
- Get the php template file from other theme folder
- Unrendered content Cornerstone through REST API
- wp_remote_get returns an error for valid URL
- Ajax call to my WordPress website from an external application [duplicate]
- Problem with Woocommerce REST API Authentication
- How Do I Add User Custom Field to REST API Response?
- Unable to set right time in admin and frontend template
- Easiest way to show total number of subpages
- Switching between custom templates in a post type of the admin menu
- Use template for posts with a particular category grandparent
- using woocommerce_template_single_add_to_cart in shop-loop – javascript issues [closed]
- Add a Second Menu to a theme that only support 1 menu
- Custom excerpt function re-factoring
- Inject PHP code into “sidebar-content” – code before my WooCommerce sidebar widget?
- How to display user nickname (not display name) in PHP template?
- Custom Template 404 for specific custom post type
- Custom field value not saving when it contains a URL?
- Automatically add custom CSS to new posts using a category template
- Why is the post meta[] empty when I make a call to the wordpress rest api?
- creating a second image attachment template?
- Issues getting PHP to display in category pages
- How do I start using an external API and PHP for a WordPress.org page?
- Store a default value for a transient on plugin activation
- Secondary navigation menu on one page
- Enable custom logo upload if logo is not in header
- how to show only specific category for a template
- Can’t print Yoast meta description into page template (syntax error, unexpected ‘.’) [closed]
- Using same variable names in files added with get_template_part()
- Create a Blog Template Page
- Showing latest post without 301 redirect
- WordPress template page name displayed on screen
- single.php with different look by category
- Removing WordPress Footer -without access to PHP code?
- Why is a wp function used in current PHP namespace’s callback not resolved to global scope?
- Permission callback to check if user has application password
- Multiple requests external data api dynamic block gutenberg
- Create page template via functions.php?
- Simple WordPress endpoint route doesn’t work
- What’s a good way to allow overwriting files within a child theme if I want the same folder structure?
- WC_Customer delete function returns error
- how to display this functions?
- is_page_template showing partial results
- Adding regular php file to site
- Custom route and query
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- Template Loop – add switch case php
- Post repeated when opening in overlay, how do I solve this? [closed]
- REST API works in browser and via AJAX but fails via cURL
- Gravity Forms merge tags in templates?
- Unable to render custom field after attempt to generate a list of recent post in page template
- pass html code to worpdress
- Getting a WordPress tag to print inside of a traditional php echo
- Flatten Responses returned via WP REST API via WP_Error for obfuscation
- WP_REST_Response – How to return Gzip answer and add Content-encoding header?
- Generate images with html2canvas and the woocommerce api
- WordPress api post image raw data without being blank in media library
- Prevent header and footer from loading on specific pages with template or plugin
- Display metabox galleries on specific page template in admin editor
- Display WordPress archive template page in 3 columns and not 1 column [closed]
- Run do_shortcode on php template using JS function
- How to hardcode header and footer in WP?
- WordPress 5.6 Application Passwords
- Trouble Accessing Gravity Forms API (GFAPI)
- Call WP Rest-Api to GET /users/me returned NOTHING in console
- WooCommerce REST API AJAX Auth – 401 response
- Looping through and combining calls to Woocommerce REST API
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- If is_page elseif is_page not working like I want it to
- Require advice handling a URL redirect from a Third Party. URL Params need to populate and then forward to payment
- How can i get the same ajax result using WP REST API instead of admin-ajax?
- missing admin bar and widget in a template
- How to include a function in a template with template tag
- WP HTTP API call response
- My own theme’s custom widget areas are not working
- How to call a certain object/menubar in a PHP file
- AdWords API with WP
- how to register a second page-template
- why is markup routinely placed in functions in wordpress?
- Loop on a wordpress Page instead of content coming from the WP text editor
- How to pass and validate nonce in custom REST routes
- Create custom API endpoint to change custom header image
- Why is this specific API request failing when sending via wp_remote_post?
- REST API custom endpoints for metaboxes
- How can one use variables in a template or template part without polluting the global scope?
- Need Help With Making Full-Width Template for Blog Posts (common methods aren’t working)
- wordpress-plugin (widget) that performs a Neaby-search on the openstreetmap-endpoint: around x find y
- Can’t make an external api call in php side of wordpress child theme