5

I need to create a single post with title, content and excerpt with this command as it's described in the utility documentation. Could you please show me an example of how to use it? I couldn't find nor in official documentation neither on Google. Thanks!

  • github.com/wp-cli/wp-cli/wiki – kaiser Sep 27 '12 at 23:33
  • There are no examples how to create a post. – Sergei Basharov Sep 28 '12 at 8:00
  • I never used it, but found it within 20secs.: wp generate posts --count=1000 generates 1k posts for you. Just read yourself please. – kaiser Sep 28 '12 at 12:44
  • There is also a command wp post create, that's what I am asking about. I don't want to generate dummy posts, I need to create a single post with title, content and excerpt. – Sergei Basharov Sep 28 '12 at 12:59
  • So then update your post with an info and a link and we start from the beginning. – kaiser Sep 28 '12 at 13:03
4

If you type wp help post create you will get all the info you need.

Example:

wp post create --post_type=page --post_status=publish --post_title='A new page'
2

If you look at the code for the create method, you'll see that it takes 2 parameters:

    public function create( $args, $assoc_args ) 

$args doesn't seem to be used - $assoc_args is the array passed to the wp_insert_post function from WordPress core. The linked Codex page explains the array parameters.

1

In case you have many post to create, you can create a dedicated folder with all your posts as text documents, using post_title as the txt file titles.

In this very same folder, create a bash file named wp-post-create--loop-files.sh with the following :

#!/bin/bash
FILES=*.txt
for f in $FILES
do
  echo "Processing $f file..."
  # TEXTFILE = $f
  # take action on each file. $f store current file name
  # cat $TEXTFILE
  wp post create "$f" --post_category=3 --post_title="$f" --user=3 
done

Then you can create all your posts in a blink by executing sh wp-post-create--loop-files.sh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.