728x90
반응형
728x170
PostID 기준으로 Post 를 구하는 방법입니다.
기본 : 'WordPressPCL' Nuget 패키지 설치
GetByIDAsync 메서드를 사용해 PostID 기준으로 Post 데이터를 가져옵니다.
private async void getPostButton_Click(object sender, EventArgs e)
{
this.logTextBox.Text += $"Get 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)
{
this.logTextBox.Text += $"ID : {postID} Find Complete!" + Environment.NewLine;
this.logTextBox.Text += $"{post.Content.Rendered}" + Environment.NewLine;
}
else
{
this.logTextBox.Text += $"ID : {postID} Not Exist!" + Environment.NewLine;
}
}
catch (Exception ex)
{
this.logTextBox.Text += ex.ToString() + Environment.NewLine;
}
}
Post 를 만들어 postIdTextBox 에 PostID 값을 넣고 그값을 기준으로 Post 데이터를 GetByIDAsync 메서드를 이용해 가져옵니다.
결과
728x90
반응형
그리드형
'C# > WordPress' 카테고리의 다른 글
[C#/WordPress] WordPress API - Post 수정하기 (0) | 2023.09.15 |
---|---|
[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 |