0
votes

I'm new to WordPress programming and I'm trying to connect to WordPress REST API and send a new post with content and many tags.

I can connect to API and send a new post but I can't add tags to those posts. I want to add tags using tag names and not IDs and it seems it is not possible. I searched over the internet and I think I should use wp_set_post_tags function but I don't know how to use this function because there is no manual for that.

My PHP web app makes some new content and tags and subject and I want to post these content to WordPress automatically using API. Can someone help me how should I send a new post to WordPress and add tags to those posts using tag names and not IDs because I generate those tags using my app and some of them might be existing in WordPress database?

So I want to add tags just like WordPress editor, separate those tags with a comma and add them to new posts.

1

1 Answers

1
votes

You need to send the tags seperately, and store the returned ID of each tag.
Just create an array called $wp_tag_ids[]; Then do a foreach loop through your stored tags.
If you've stored your tags in a comma seperated format you'll need to explode(',', $post->tags) then loop through those as you post them up to wordpress.

You can then reference those ID's in an array when you post them back in the /wp/v2/posts endpoint.