PHP code example of megumi / wp-post-helper

1. Go to this page and download the library: Download megumi/wp-post-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

megumi / wp-post-helper example snippets


$args = array(
    'post_name'    => 'slug',                  // slug
    'post_author'  => '1',                     // author's ID
    'post_date'    => '2012-11-15 20:00:00',   // post date and time
    'post_type'    => 'post',                 // post type (you can use custom post type)
    'post_status'  => 'publish',               // post status, publish, draft and so on
    'post_title'   => 'title',                 // post title
    'post_content' => 'content',               // post content
    'post_category'=> array( 1, 4 ),           // category IDs in an array
    'post_tags'    => array( 'tag1', 'tag2' ), // post tags in an array
);

$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();

$args = array(
    ...
);

$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();

$attachment_id = $helper->add_media(
    'http://placehold.jp/100x100.png', // path or url
    'title',
    'description',
    'caption',
    false
);

$args = array(
    ...
);

$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();

$post->add_meta(
   'meta_key',  // meta key
   'meta_val',  // meta value
   true         // add it as unique (true) or not (false)
);

$args = array(
    ...
);

$helper = new Megumi\WP\Post\Helper( $args );
$post_id = $helper->insert();

$post->add_field(
   'field_xxxxxxxxxxxxx',   // key
   'field_val'          // value
);