Skip to content

Instantly share code, notes, and snippets.

@ahmadawais
Last active May 21, 2018 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadawais/3f37580dee585eeaad071bf3b01c8a42 to your computer and use it in GitHub Desktop.
Save ahmadawais/3f37580dee585eeaad071bf3b01c8a42 to your computer and use it in GitHub Desktop.
var WPAPI = require( 'wpapi' );
var RSVP = require('rsvp');
// Using the RSVP.hash utility for convenience and parallelism
RSVP.hash({
categories: wp.categories().slug( 'it-services' ),
tags1: wp.tags().slug('hotel-name'),
tags2: wp.tags().slug('march-events')
}).then(function( results ) {
// Combine & map .slug() results into arrays of IDs by taxonomy
var tagIDs = results.tags1.concat( results.tags2 )
.map(function( tag ) { return tag.id; });
var categoryIDs = results.categories
.map(function( cat ) { return cat.id; });
return wp.posts()
.tags( tags )
.categories( categories );
}).then(function( posts ) {
// These posts are all fiction, either magical realism or historical:
console.log( posts );
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment