diff --git a/lib/posts.js b/lib/posts.js index 62900ab5..b13794ab 100644 --- a/lib/posts.js +++ b/lib/posts.js @@ -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 @@ -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 @@ -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; diff --git a/tests/unit/lib/posts.js b/tests/unit/lib/posts.js index f98ac415..25d0baef 100644 --- a/tests/unit/lib/posts.js +++ b/tests/unit/lib/posts.js @@ -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' ); });