UNPKG

2.21 kBMarkdownView Raw
1
2# Post
3
4`Post` handler class.
5
6### Create a `Post` instance from Site
7
8```js
9var wpcom = require('wpcom')('<your-token>');
10var post = wpcom
11 .site('blog.wordpress.com')
12 .post(342);
13});
14```
15
16## API
17
18### Post(id, site, WPCOM);
19
20Create a new `Post` instance giving `id`, `site-id` and `WPCOM` instance.
21
22```js
23var post = Post('<id>', '<site-id>', WPCOM);
24```
25
26### Post(data, site, WPCOM);
27
28Create a new `Post` instance giving `data` object, `site-id` and `WPCOM` instance.
29
30```js
31var data = { id: '<id>', slug: '<slug>' };
32var post = Post(data, '<site-id>', WPCOM);
33```
34
35### Post.id(id)
36
37Set post `id`
38
39### Post.slug(slug)
40
41Set post `slug`.
42
43### Post#get([query, ]fn)
44
45Get post data by `id` or `slug` depending on which of these parameter is
46defined, giving priority to `id` over `slug`
47
48```js
49post.get(function(err, data){
50 // post data object
51});
52```
53
54### Post#getBySlug(fn)
55
56Get post data by `slug`. `slug` must have been previously defined through the
57constructor or using the `.slug()` method.
58
59```js
60var post = Post({ slug: '<slug>' }, '<site-id>', WPCOM);
61post.getBySlug(function(err, data){
62 // post data object
63});
64```
65
66### Post#add(data, fn)
67
68### Post#update(data, fn)
69
70### Post#del(fn) - Post#delete(fn)
71
72Delete a Post. Note: If the post object is of type post or page and the trash
73is enabled, this request will send the post to the trash. A second request will
74permanently delete the post.
75
76### Post#likesList(fn)
77
78Get post likes list
79
80```js
81wpcom
82.site('blog.wordpress.com')
83.post(342)
84.likesList(function(err, list){
85 // like `list` object
86});
87```
88
89### Post#like()
90
91Create and return a new `Like` instance.
92More info in [Like doc page](./like.md).
93
94```js
95var like = wpcom.site('blog.wordpress.com').post(342).like();
96```
97
98### Post#reblog()
99
100Create and return a new `Reblog` instance.
101More info in [Reblog doc page](./reblog.md).
102
103```js
104var reblog = wpcom.site('blog.wordpress.com').post(342).reblog();
105```
106
107### Post#comment()
108
109Create and return a new `Comment` instance.
110More info in [Comment doc page](./comment.md).
111
112### Post#comments()
113
114Recent recent comments
115
116```js
117wpcom
118.site('blog.wordpress.com')
119.post(342)
120.comments(function(err, list){
121 // post comments list
122});
123```