1

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.

4
  • 1
    I think there's some ambiguity in your question, why do you need to call this? Where do you need to call this? And when you say you're using the REST API, can you explain some more? Are you calling the built in endpoints core adds for posts etc? Or are you building your own? What does your PHP app do? Is it an importer script? Data migration? Syndication? Edit your question to include as much details as possible to answer as many of those Q's as you can, even if the response is that you don't know
    – Tom J Nowell
    Commented Jan 9, 2020 at 16:13
  • You don't run functions directly over the REST API. I think you make PUT requests to the /wp-json/wp/v2/posts/98 endpoint with a JSON object containing a "tags" value for the tags you'd like to set.
    – Rup
    Commented Jan 9, 2020 at 16:15
  • Thanks. I think I find out what to do. I read WordPress endpoint route creation. I should set a route and inside that route I should run a function to add tags.
    – arashnz
    Commented Jan 9, 2020 at 21:25
  • The "proper" way to do this is to create the tags first, then use the new IDs that are returned to create the post. Trying to update and create multiple resources at once is not how REST is supposed to be used. Commented Jan 10, 2020 at 4:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.