wp_insert_post Custom Post Type |
X

Congrats, You are Subscribed to Receive Updates.

wp_insert_post Custom Post Type


Introduction

wp_insert_post custom post type is simple to insert a custom post type.  This article continues from my previous article regarding wp_insert_post. If you didn’t check it take a look at here wp_insert_post Example. Also, I added a comment line there for the custom post types. Let’s take a look the example program for better understanding.

Custom Post Type

If you created a custom post type, you must have the custom post type. For example, I am creating a custom post type as jobs to understand, how to insert a custom post type for job.  Let’s program to create a job in it.

wp_insert_post( 
 	array( 'ID' => (if its update, you have to provide existing post, you can use the ID to update it), // optional
 		'post_author' => (author ID), 
 		'post_content' => $_POST['content'], // content of the article,
  		'post_title' => $_POST['title'], // title of the article
  		'post_status' => 'publish', // I just published the post directly, but you can change the status as of your need
  		'post_type' => 'jobs', // here is my custom post type, you can change it to your own type there.
  		'post_category' => array(25, 35),
  		'tax_input' => array('WordPress', 'post')
  	) 
);

That’s it.

The main part is here.

'post_type' => 'jobs',

You can change it to your desired one. If you need any help or doubt clarification regarding the custom post type. comment it on next tab, I will help you in this.

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, PHP and Data Analyst. Database Management Advance Level

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar