0
私は問題を抱えていて、何か基本的なものがないと思っていました。私はWordPressで "今"から1ヶ月未満の公開日を持つ投稿を一覧表示する機能を作っています。これは、time()を使用して現在の時刻から2419200(30日)を引くことによって行います。それから私は30日以上前に投稿を受け取ります。しかし、私の関数はこの範囲を間違って解釈し、2週間の範囲内にある投稿のみを提供します!公開日を「1ヶ月前」のUNIX時刻と比較する
この問題に加えて、この関数には多くのことが起こっているので、この問題については$ range、$ limit、および$ publish_dateという変数に従ってください。テスト目的のために、私は変数を "monthly"に手作業で設定することに注意してください。代わりにあなたが先月で作成したポストを返す必要があります日付範囲
$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
このクエリを使用してクエリを実行することができ、すべての投稿の上に行くの
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。ありがとうございました。非常に便利。 –