Bir problem üzerinde sıkışıp kaldım ve belki de temel bir şeyi özlüyorum. WordPress'de, yayınları "artık" dan bir aydan daha kısa bir tarihte listeleyen bir işlev yapıyorum. Bunu, zamandan() kullanarak 2419200'ü (30 gün) geçerli saatten çıkararak yapıyorum. Daha sonra> 30 gün önce olan yayınları alıyorum. Bununla birlikte, işlevim bu aralığı yanlış yorumluyor ve yalnızca 2 hafta içinde olan gönderileri sunuyor!Post yayınlanma tarihinden "bir ay önce" unix zamanının karşılaştırılması
Bu soruna ek olarak bu işlevde çok fazla şey var, bu yüzden özür dileriz, ancak bu konu için $ range, $ limit ve $ publish_date değişkenlerini izleyin. Test amaçlı olarak değişkeni başlangıçta "aylık" olarak ayarlıyorum. Bunun yerine son bir ay içerisinde oluşturulan yazı dönmelidir bir tarih aralığı
$args = array(
'date_query' => array(
array(
'column' => 'post_date_gmt',
'after' => '1 month ago',
)
),
'posts_per_page' => -1,
);
$query = new WP_Query($args);
//DO YOUR STUFF WITH THE RESULTS
Bu sorgu kullanarak bir sorgu çalıştırabilirsiniz tüm mesajların üzerine gitmekten
function send_archive() {
$range = 'monthly';
$now = time();
switch ($range) {
case 'monthly' :
$limit = ($now - 2419200); // 30 days
break;
case 'weekly' :
$limit = ($now - 604800);
break;
case 'daily' :
$limit = ($now - 86400);
break;
}
$post_types = get_post_types();
$posts = get_posts(array('post_type' => $post_types));
$all_users = get_users();
foreach ($all_users as $user) {
$excluded = excluded_admin($user->user_login);
echo 'excluded is: ' . $excluded . '<br />';
echo 'user_login is: ' . $user->user_login . '<br />';
if ($excluded != 'excluded') {
$frequency = get_user_meta($user->ID, 'iw_notify_frequency', true);
echo 'frequency is: ' . $frequency . '<br />';
echo 'Range is: ' . $range . '<br />';
echo 'Limit is: ' . date('D, d M Y H:i:s',$limit) . '<br />';
$posts_in_range = '';
$counter = 0;
$to = '';
$subject = '';
$headers = '';
if ($frequency == $range) {
$posts_in_range = get_option('iw-notify-greeting');
$posts_in_range .= '<p>' . strtoupper($range) . ' digest of posts from the City of Mukilteo</p>';
foreach ($posts as $post) {
$published_date = strtotime($post->post_date_gmt);
$posts_in_range .= 'published_date: ' . $published_date. '<br />';
$posts_in_range .= 'limit: ' . $limit . '<br />';
$posts_in_range .= 'title: ' . $post->post_title . '<br />';
if ($published_date > $limit) {
$match = has_user_selected_terms($user->ID, $post->ID);
if ($match != '') {
$headers = 'Content-type: text/html;charset=utf-8' . "\r\n";
$posts_in_range .= $post->post_title;
$posts_in_range .= ' - published ' . date('M, d', $published_date) . '<br />';
$posts_in_range .= $post->post_excerpt . '<br />';
$posts_in_range .= get_permalink($post->ID);
$posts_in_range .= '<br /><br />';
$counter++;
}
}
}
}
$posts_in_range .= get_option('iw-notify-unsubscribe') . '<br />----<br />';
if ($counter != 0) {
$to = $user->user_email;
$subject = ucfirst($range) . ' archive from the City of Mukilteo';
$headers = 'Content-type: text/html;charset=utf-8';
$headers .= 'From: ' . get_option('from-name') . '<' . get_option('from-email') . '>' . "\r\n";
$content = $posts_in_range;
wp_mail($to, $subject, $content, $headers);
echo "Email sent to " . $user->display_name . '<br />';
echo $to . '<br />';
echo $subject .'<br />';
echo $headers . '<br />';
echo $posts_in_range . '<br />';
//echo $user->display_name . '<br />';
//echo $posts_in_range;
}
}
}
}
Oh wow. Bunun için teşekkürler. Çok kullanışlı. –