• Resolved oldmankit

    (@oldmankit)


    I’m trying to create new posts using WordPress CLI. So far I can create a post, but not set it’s taxonomy, because I don’t know the format for doing this. My command looks like this:

    wp post create \
    	--post_title='testing' \
    	--post_status='draft' \
    	--post_type='class_notes' \
    	--tax_input=( ["course"] = "en213" )

    The line I need help with is the last one. I don’t know how to format that array correctly. I will need to have set several taxonomies all at the same time.

    I do appreciate any help with this.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Hi,

    I don’t think that’s possible right now:
    https://github.com/wp-cli/wp-cli/issues/1323

    You could try wrapping the create post command inside the term (add/set) command:
    https://developer.www.ads-software.com/cli/commands/post/term/

    
    wp post term set $(wp post create \
    	--post_title='testing' \
    	--post_status='draft' \
    	--post_type='class_notes' \
    	--porcelain) course "en213"
    Thread Starter oldmankit

    (@oldmankit)

    You’ve gone way beyond what I could’ve managed there @keesiemeijer.

    The issue now is that I need to be able to set multiple different taxonomies on the created post. On the post term reference (https://developer.www.ads-software.com/cli/commands/post/term/) there isn’t any information on how to set more than one different taxonomy at a time. I tried the following but it created three different values for the “course” taxonomy (en213, semester, 2018a), instead of creating one value for the “semester” taxonomy (2018a) in addition to the “course” taxonomy (en213).

    wp post term set $(wp post create \
    	--post_title='testing' \
    	--post_status='draft' \
    	--post_type='class_notes' \
    	--porcelain) course "en213" semester "2018a"

    If wp post create was able to return an id of the created post, I guess this would be possible by running the post term set command on multiple lines, one line for each different taxonomy. But again from the wp post create documentation I can’t see how to return the post id.

    Moderator keesiemeijer

    (@keesiemeijer)

    wp post create returns the post id if you use the --porcelain parameter.

    Try it with this:

    
    post_id=$(wp post create \
    	--post_title='testing' \
    	--post_status='draft' \
    	--post_type='class_notes' \
    	--porcelain); \
    wp post term set "$post_id" course "en213"; \
    wp post term set "$post_id" semester "2018a"
    Thread Starter oldmankit

    (@oldmankit)

    Thank you @keesiemeijer, you’ve totally solved it for me. I hadn’t noticed what --porcelain was actually doing.

    Thank you so much for helping me.

    • This reply was modified 6 years, 6 months ago by oldmankit.
    Moderator keesiemeijer

    (@keesiemeijer)

    You’re welcome ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How do I set the taxonomy for a new post using wp-cli?’ is closed to new replies.