Created
December 23, 2013 23:02
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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"; |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not use wp-cli? hmmm....