728x90
반응형
728x170
WordPress API 를 이용하여 Post 내용을 수정하는 방법입니다.
기본 : 'WordPressPCL' Nuget 패키지 설치
GetByIDAsync 메서드를 이용해 PostID 기준 Post 데이터를 가져오고 내용을 수정하여 UpdateAsync 메서드를 통해 Post 데이터를 수정합니다.
private async void updateButton_Click(object sender, EventArgs e)
{
this.logTextBox.Text += $"Update Post -----------------------------------------------" + Environment.NewLine;
string baseURL = "https://wordpress주소.kr/wp-json/";
string userID = "사용자명";
string applicationPassword = "응용프로그램비밀번호";
WordPressClient client = new WordPressClient(baseURL);
client.Auth.UseBasicAuth(userID, applicationPassword);
try
{
int postID = int.Parse(this.postIdTextBox.Text);
Post post = await client.Posts.GetByIDAsync(postID, useAuth: true);
if (post != null)
{
post.Title = new Title("포스트 제목 수정");
post.Content = new Content("포스트 내용 수정");
Post postUpdated = await client.Posts.UpdateAsync(post);
this.logTextBox.Text += $"ID : {postID} Update Complete!" + Environment.NewLine;
Post modifypost = await client.Posts.GetByIDAsync(postID, useAuth: true);
this.logTextBox.Text += $"제목 : {modifypost.Title.Rendered}" + Environment.NewLine;
this.logTextBox.Text += $"내용 : {modifypost.Content.Rendered}" + Environment.NewLine;
}
else
{
this.logTextBox.Text += $"ID : {postID} Not Exist!" + Environment.NewLine;
}
}
catch (Exception ex)
{
this.logTextBox.Text += ex.ToString() + Environment.NewLine;
}
}
Create Post 버튼클릭으로 Post 를 만든 후 Update Post 버튼으로 Post 를 수정한 후 Post 데이터를 다시 가져와 수정된 내용을 확인합니다.
결과
728x90
반응형
그리드형
'C# > WordPress' 카테고리의 다른 글
[C#/WordPress] WordPress API - Post 구하기 (0) | 2023.09.13 |
---|---|
[C#/WordPress] WordPress API - Post 삭제하기 (0) | 2023.09.12 |
[C#/WordPress] WordPress API - Post 쓰기 (0) | 2023.09.06 |
[C#/WordPress] WordPress API - Post 항목 가져오기 (0) | 2023.08.30 |
[링크] 10 Awesome WordPress Plugin (0) | 2023.01.25 |