WordPress Wp_insert_post Example

0 66

wp_insert_post example and wp_insert_post in WordPress and wp_insert_post custom post type. wp_insert_post featured image example. Many articles and many examples already there in many blogs and forums. Here I am going to explain nothing but how to use it effectively the wp_insert_post to add new post with your program.


The below function helps to insert or update post with your post through programmatically. Already the syntax available in codec page. I just wrote in simply the syntax without much explanations.

The above one is simple  and I don’t want to give you all and make you feel uncomfortable with it.  Widely these arguments are used, if you want to know more and depth in parameter types, take a  look at its codec page.

Wp_insert_post Hook

There is one more thing, there is an action hook wp_insert_post, which helps to trigger certain functions and perform some operation while publishing or updating a post. here is the sample

If you wish to add a featured image to your post, just do the following thing.

Wp_insert_post Featured Image

There are several things together in a post. Sometimes you need to add a thumbnail image to the post. If you are already uploaded an image to media library and you have the attachment Id, than its so simple to do it. just do the following thing.

set_post_thumbnail($Post_ID, $attach_ID);

You might also like More from author

Leave A Reply

Your email address will not be published.