module WPDB::Termable
Public Instance Methods
add_term(term, taxonomy, description, count)
click to toggle source
For objects that have a relationship with termtaxonomies, this module can be mixed in and gives the ability to add a term directly to the model, rather than creating the relationship yourself. Used by Post
and Link
.
# File lib/ruby-wpdb/term.rb, line 19 def add_term(term, taxonomy, description, count) if term.respond_to?(:term_id) term_id = term.term_id else term_id = term.to_i end term_taxonomy = WPDB::TermTaxonomy.where(term_id: term_id, taxonomy: taxonomy).first unless term_taxonomy term_taxonomy = WPDB::TermTaxonomy.create( term_id: term_id, taxonomy: taxonomy, description: description, count: count ) else term_taxonomy.count += count end add_termtaxonomy(term_taxonomy) end