This class InsertPost is use to insert post programmatically, for example you can insert dummy post.
File need to include:
Following file contain the class, you can include in your theme or plugin or application to use of class.
classes/class-insert-post.php
Example file:
Following file is contain example code of usages of class.
functions/functions-insert-post.php
Code sample:
$args = array( 'args' => array( //'ID'=> 30, 'post_author'=> 1, 'post_title'=> 'Post Title Demo', 'post_content'=> 'Post Content Demo', 'post_type'=> 'post', 'post_status'=> 'publish', ), 'meta_fields' => array( 'meta_field_1' => 'Hello Meta field 1', 'meta_field_2' => 'Hello Meta field 2', 'meta_field_3' => array('Hello Meta field 1','Hello Meta field 2'), ), ); $InsertPost = new InsertPost(); $PostID = $InsertPost->insert_post($args); var_dump($PostID);
Arguments:
Argument | Type | Example |
---|---|---|
args | Array | Array of Arguments supported by wp_insert_post |
meta_fields | Array | Array of meta field key and value, value can be string, integer or array. |