Skip to content

Instantly share code, notes, and snippets.

@cheald
Created November 1, 2012 20:28
Show Gist options
  • Save cheald/3996264 to your computer and use it in GitHub Desktop.
Save cheald/3996264 to your computer and use it in GitHub Desktop.
def terms(taxonomies = [], include_taxonomies = false)
ids = relationships.map(&:term_taxonomy_id)
return [] if ids.empty?
proxy = Wordpress::Term.joins(:taxonomies).where(Wordpress::TermTaxonomy.arel_table[:term_taxonomy_id].in ids)
proxy = proxy.includes(:taxonomies) if include_taxonomies
proxy.where( Wordpress::TermTaxonomy.arel_table[:taxonomy].in(taxonomies) ) unless taxonomies.empty?
proxy.all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment