Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function PostsRequest( options ) {
* @private
* @default {}
*/
this._path = {};
this._path = { postType: 'posts' };

/**
* The URL template that will be used to assemble endpoint paths
Expand All @@ -74,7 +74,7 @@ function PostsRequest( options ) {
* @private
* @default 'posts(/:id)(/:action)(/:actionId)'
*/
this._template = 'posts(/:id)(/:action)(/:actionId)';
this._template = ':postType(/:id)(/:action)(/:actionId)';

/**
* @property _supportedMethods
Expand Down Expand Up @@ -168,4 +168,17 @@ PostsRequest.prototype.revisions = function() {
return this.auth();
};

/**
* Change the type of posts that we are querying.
*
* @method type
* @chainable
* @param {String} type A string specifying the post type to query
* @return {PostsRequest} The PostsRequest instance (for chaining)
*/
PostsRequest.prototype.type = function( type ) {
this._path.postType = type;
return this;
};

module.exports = PostsRequest;
4 changes: 2 additions & 2 deletions tests/unit/lib/posts.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describe( 'wp.posts', function() {
it( 'should intitialize instance properties', function() {
expect( posts._filters ).to.deep.equal( {} );
expect( posts._taxonomyFilters ).to.deep.equal( {} );
expect( posts._path ).to.deep.equal( {} );
expect( posts._template ).to.equal( 'posts(/:id)(/:action)(/:actionId)' );
expect( posts._path ).to.deep.equal( { postType: 'posts' } );
expect( posts._template ).to.equal( ':postType(/:id)(/:action)(/:actionId)' );
var _supportedMethods = posts._supportedMethods.sort().join( '|' );
expect( _supportedMethods ).to.equal( 'get|head|post' );
});
Expand Down