Module: WPDB::Termable
Instance Method Summary collapse
-
#add_term(term, taxonomy) ⇒ Object
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.
Instance Method Details
#add_term(term, taxonomy) ⇒ Object
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.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby-wpdb/terms.rb', line 34 def add_term(term, taxonomy) 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) end add_termtaxonomy(term_taxonomy) end |