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