forked from wp-net/WordPressPCL
-
Notifications
You must be signed in to change notification settings - Fork 0
Working with Comments
Thomas Pentenrieder edited this page Oct 31, 2017
·
4 revisions
Here is a list of methods and examples of working with Comments
// returns all comments
var comments = await client.Comments.GetAll();
// returns comment by ID
var comment = await client.Comments.GetByID(123);
// returns comments from post
var comments = await client.Comments.GetCommentsForPost(123)
Create parametrized request
// returns result of query
var queryBuilder = new CommentsQueryBuilder();
queryBuilder.PerPage = 40;
queryBuilder.Page = 2;
queryBuilder.Before = DateTime.Now;
var comments = await client.Comments.Query(queryBuilder);
If your blog supports threaded comments (comments with direct answers) you can order and get the right depth for them with this handy extension method:
var comments = await client.Comments.GetCommentsForPost(123)
var commentsThreaded = comments.ToThreaded();
// returns created comment
var comment = new Comment()
{
Content = new Content("Comment"),
PostId = 123,
AuthorId = 1,
AuthorEmail = "[email protected]"
};
if (await client.IsValidJWToken())
{
var createdComment = await client.Comments.Create(comment);
}
// returns updated comment
var comment= client.Comments.GetByID(123);
comment.Content.Raw = "New Content";
if (await client.IsValidJWToken())
{
var updatedComment = await client.Comments.Update(comment);
}
// returns result of deletion
if (await client.IsValidJWToken())
{
var result = await client.Comments.Delete(123);
}