Skip to content

Instantly share code, notes, and snippets.

@karlazz
Created December 23, 2013 23:02
Show Gist options
  • Select an option

  • Save karlazz/8106308 to your computer and use it in GitHub Desktop.

Select an option

Save karlazz/8106308 to your computer and use it in GitHub Desktop.
Add a post type record to wp-post from command line. Doesn't take content (yet), needs work.
<?php
if (isset($argv[1])) $title = $argv[1]; else { print "Usage php wpinsert TITLE POSTTYPE \n -- POSTTYPE is optional and defaults to page\n"; exit; }
if (isset($argv[2])) $type = $argv[2]; else { print "Post type defaulting to PAGE\n"; $type="page"; }
//required include files
define('WP_DEBUG', false);
require('wp-blog-header.php');
require_once("wp-config.php");
require_once("wp-includes/wp-db.php");
//-- Set up post values
$myPost = array(
'post_status' => 'publish',
'post_type' => $type,
'post_author' => 1,
'post_title' => $title,
'comment_status' => 'closed',
'ping_status' => 'closed',
);
//-- Create the new post
$newPostID = wp_insert_post($myPost);
if ($newPostID)
print "\nNew ".$type." '". $title ."' created with id=".$newPostID."\n";
else print "\n Insert Failed! :-( \n";
@karlazz
Copy link
Copy Markdown
Author

karlazz commented Dec 23, 2013

Why not use wp-cli? hmmm....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment