-
Notifications
You must be signed in to change notification settings - Fork 1
PostsHandler
To get a new instance, either create an inline variable or use your favorite Locator:
//inline var
var handler = new PostsHandler();
//MVVMLight (or any other Locator):
SimpleIoc.Default.Register<IPostsHandler>(()=> new PostsHandler());
If you want to add the "If-Modified-Since"-Header and "User-Agent"-Header, just fill in the parameters:
//inline var
var handler = new PostsHandler(DateTime.Now, "MyAwesomeApp", "1.0.0");
//MVVMLight (or any other Locator):
SimpleIoc.Default.Register<IPostsHandler>(()=> new PostsHandler(DateTime.Now, "MyAwesomeApp", "1.0.0"));
There are several ways to get and filter posts from the WordPress API:
var posts = handler.GetPostsAsync("yourBaseUrl");
Note that you have optional parameters for pages, page counts, and order of the results.
var post = handler.GetPostAsync("yourBaseUrl", 12345);
var post = handler.GetPostBySlugAsync("yourBaseUrl", "slug");
(to get the tag ids, use the TagHandler or extract them from other objects)
var posts = handler.GetPostsByTagsAsync("yourBaseUrl", { 4567, 4568 });
var posts = handler.SearchPostsAsync("yourBaseUrl", "your search terms");
Note that you have optional parameters for pages, page counts, and order of the results.
All above calls will result in a WordPressEntitySet<TWordPressEntity>
or a WordPressEntity<TWordPressEntity>
. If there was an error on the API side, the Error
property will be filled, otherwise it will be null
and the Value
will hold the result.