Class: ActivePress::Post
- Defined in:
- lib/active_press/models/post.rb
Class Method Summary collapse
- .by_day(d) ⇒ Object
- .by_month(d) ⇒ Object
- .by_year(d) ⇒ Object
-
.search(query) ⇒ Object
Basic post search.
Instance Method Summary collapse
Class Method Details
.by_day(d) ⇒ Object
35 36 37 |
# File 'lib/active_press/models/post.rb', line 35 def self.by_day(d) where(:post_date_gmt => (d.beginning_of_day..d.end_of_day)) end |
.by_month(d) ⇒ Object
31 32 33 |
# File 'lib/active_press/models/post.rb', line 31 def self.by_month(d) where(:post_date_gmt => (d.beginning_of_month..d.end_of_month)) end |
.by_year(d) ⇒ Object
27 28 29 |
# File 'lib/active_press/models/post.rb', line 27 def self.by_year(d) where(:post_date_gmt => (d.beginning_of_year..d.end_of_year)) end |
.search(query) ⇒ Object
Basic post search.
Requires FULLTEXT indexes on post_name and post_content
alter table wp_posts add fulltext(post_title, post_content);
23 24 25 |
# File 'lib/active_press/models/post.rb', line 23 def self.search(query) where(['MATCH (post_title, post_content) AGAINST (?) > 0', query]) end |
Instance Method Details
#meta ⇒ Object
57 58 59 60 61 62 |
# File 'lib/active_press/models/post.rb', line 57 def .inject({}) do |hash, | hash[..to_sym] = . hash end end |
#next_post ⇒ Object
39 40 41 42 43 44 |
# File 'lib/active_press/models/post.rb', line 39 def next_post self.class.published.where(['id != ?', self.id])\ .where(:post_type => self.post_type)\ .where(['post_date_gmt >= ?', self.post_date_gmt])\ .order('post_date_gmt ASC').limit(1) end |
#previous_post ⇒ Object
46 47 48 49 50 51 |
# File 'lib/active_press/models/post.rb', line 46 def previous_post self.class.published.where(['id != ?', self.id])\ .where(:post_type => self.post_type)\ .where(['post_date_gmt <= ?', self.post_date_gmt])\ .order('post_date_gmt DESC').limit(1) end |
#to_param ⇒ Object
53 54 55 |
# File 'lib/active_press/models/post.rb', line 53 def to_param post_name end |