Forum Replies Created
-
In reply to: WP-API create a new topic and assign a parent forum
Certainly! In the WordPress REST API, creating a new topic and assigning it to a parent forum involves utilizing the
wp/v2
endpoints for both forums and topics. To achieve this, you can follow these steps:### 1. Get the Forum ID
Firstly, you’ll need to know the ID of the parent forum to which you want to assign the new topic. You can retrieve this ID by making a GET request to the forums endpoint, typically/wp/v2/forums
.For example:
`http
GET /wp/v2/forums
`
### 2. Create a New Topic
Make a POST request to the topics endpoint, usually/wp/v2/topics
, providing the necessary parameters includingtitle
,content
, andforum
to link it to the specific forum.For example:
`http
POST /wp/v2/topics
Content-Type: application/json{
“title”: “New Topic Title”,
“content”: “Content of the new topic”,
“forum”: <forum_id>
}
`
Replace<forum_id>
with the ID of the parent forum retrieved from step 1.### Example Using cURL
Using cURL, the process might look something like this:
`bash
curl -X POST -H “Content-Type: application/json” -d ‘{“title”:”New Topic Title”,”content”:”Content of the new topic”,”forum”:1}’ https://yoursite.com/wp-json/wp/v2/topics
`
Replacehttps://yoursite.com
with your actual WordPress site URL and1
with the ID of the desired forum.Remember to authenticate the API request if your WordPress site requires authentication for creating new content.
This approach allows you to create a new topic and assign it to a parent forum via the WordPress REST API. Adjust the endpoint URLs and parameters as needed based on your specific WordPress configuration.