How to add categories, tags and custom fields when creating posts?
See original GitHub issueThis doesn’t seem to work for me
function createPost(){
wp.posts().create({
title: data.title,
content: data.subtitle,
tag: [ 'vegan', 'dinner' ],
category: [ 'berlin', 'copenhagen' ],
}).then(function( response ) {
// "response" will hold all properties of your newly-created post,
// including the unique `id` the post was assigned on creation
console.log("post created with id: " + response.id );
});
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:6
Top Results From Across the Web
How to Add Categories to a Custom Post Type in WordPress
Add Categories to a Custom Post Type with a Plugin. If you're a beginner, we recommend using the Custom Post Type UI plugin...
Read more >Creating Custom Content in WordPress: Custom Post Types
You can use the same key again and again for multiple posts, but each will have a unique value. WordPress also gives each...
Read more >Display Custom Fields on Category, Tags and Taxonomy
I want to Add Custom Field on All Tags, Category, and Custom Post Type (Taxonomy) but with the below code get custom field...
Read more >WordPress Custom Post Types: The All-In-One Guide ... - Kinsta
And once you have created a custom post type, how do you add to it, ... You can add categories and tags to...
Read more >Convert custom fields to post categories
Most parameters might be added to the query like meta_query , category . wp_create_category() , will create a category once. wp_set_post_terms() ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The chaining methods
.category
and.tag
are only for filtering collections; if you’re creating a post, you’ll want to include the.tags
or.categories
arrays in the post data object, as you had it in the initial post up above. So, if we imagine ‘vegan’ is tag ID#1
, ‘dinner’ is ID#2
, category ‘berlin’ is ID#3
, and ‘copenhagen’ is#4
:Hope that helps!
@mrkrumhausen I do not believe so, but that’d be a good question to ask over on the main WP REST API repository.
I’m going to close this out, thanks for raising the issue and let me know if you run into any further trouble!