forked from wp-net/WordPressPCL
-
Notifications
You must be signed in to change notification settings - Fork 0
Working with Categories
Maxim Polushin edited this page Sep 21, 2017
·
3 revisions
Here is a list of methods and examples of working with Categories
// returns all categories
var categories = await client.Categories.GetAll();
// returns category by ID
var category = await client.Categories.GetByID(123);
Create parametrized request
// returns result of query
var queryBuilder = new CategoriesQueryBuilder();
queryBuilder.PerPage = 40;
queryBuilder.Page = 2;
queryBuilder.Before = DateTime.Now;
var categories = await client.Categories.Query(queryBuilder);
// returns created category
var category = new Category()
{
Name = "Title 1",
Description = "Content"
};
if (await client.IsValidJWToken())
{
var createdCategory = await client.Categories.Create(category);
}
// returns updated category
var category = client.Categories.GetByID(123);
category.Name = "New Name";
if (await client.IsValidJWToken())
{
var updatedCategory = await client.Categories.Update(category);
}
// returns result of deletion
if (await client.IsValidJWToken())
{
var result = await client.Categories.Delete(123);
}