Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Vladimir Zhelnov // neatek.ru // neatek.pw
- // functions.php (Wordpress)
- function get_archive_date($date = '', $before = false, $term = 0) {
- global $wpdb;
- $res = array();
- if(!empty(strtotime($date))) {
- $date = date('Y-m-d H:i:s' ,strtotime($date));
- if($before) {
- $x = '<';
- }
- else {
- $x = '>';
- }
- $sql = "SELECT year(post_date) FROM ".$wpdb->posts."";
- if($term > 0) {
- $sql .= " INNER JOIN ".$wpdb->term_relationships."
- ON ".$wpdb->posts.".ID = ".$wpdb->term_relationships.".object_id
- WHERE
- `term_taxonomy_id`='".$term."'";
- }
- $sql .= "AND `post_status`='publish'
- AND `post_type` <>'attachment'
- AND post_date ".$x." '".$date."'
- GROUP by year(post_date)
- ORDER by year(post_date) DESC";
- $res = $wpdb->get_col($sql);
- }
- return $res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement