
jgbustos
By: a guest on Jun 7th, 2009 | syntax:
PHP | size: 1.96 KB | hits: 668 | expires: Never
<?php
/*
Plugin Name: Post Repeater
Plugin URI: http://blog.vishalon.net/Post/90.aspx
Description: This plugin repeats a particular post every year/month/week. Set the custom field Key=REPEATON, Value=MM/DD for the yearly repeat, Value=01/02...12 for monthly repeat, Value=Sun/Mon/Tue/Wed/Thu/Fri/Sat for weekly repeat.
Author: Vishal Monpara
Version: 1.1
Author URI: http://www.vishalon.net/
*/
add_filter('query','PostRepeater');
function PostRepeater($query)
{
global $wpdb;
if (strpos($query,'SELECT SQL_CALC') && ! strpos($query, ' LIKE ')) {
// if (preg_match('/SELECT SQL_CALC/', $query) && ! preg_match('/ LIKE /', $query)) {
$uri = $_SERVER['REQUEST_URI'];
{
$time = time()+(get_settings
('gmt_offset') * 3600
);
$split = explode('ORDER BY', $query);
$current_plugins = get_option('active_plugins');
if (!in_array('wp-sticky/wp-sticky.php', $current_plugins)) {
$orderby = 'ORDER BY N,'. $split[1];
$query = str_replace(' FROM ',', 2 AS N FROM ',$split[0
]);
$extra_column = "1 AS N";
} else {
$orderby = 'ORDER BY '. $split[1];
$orderby = str_ireplace("{$wpdb->prefix}sticky.", '', $orderby);
$query = $split[0];
$extra_column = "2 as sticky_status";
}
$query = "(" .$query. ") UNION ALL ";
$query = $query.
"( SELECT $wpdb->posts.*, $extra_column FROM $wpdb->posts
INNER JOIN $wpdb->postmeta
ON $wpdb->posts.ID = $wpdb->postmeta.post_id
WHERE $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'post'
AND $wpdb->postmeta.meta_key = 'REPEATON' AND
($wpdb->postmeta.meta_value = '". gmdate('m/d',$time) . "'
OR $wpdb->postmeta.meta_value = '". gmdate('d',$time) . "'
OR $wpdb->postmeta.meta_value = '". gmdate('D',$time) . "')
ORDER BY post_date_gmt DESC) ".
$orderby;
}
}
return $query;
}
?>