Skip to content

Instantly share code, notes, and snippets.

@marushu
Forked from miya0001/gist:1378387
Created November 19, 2011 04:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marushu/1378425 to your computer and use it in GitHub Desktop.
Save marushu/1378425 to your computer and use it in GitHub Desktop.
指定された期限内の記事だけを取得する
<?php
/*
現在の日時から2日後のタイムスタンプを保存する
$d = 2 * 60 * 60 * 24; // 2日間
$expire = current_time('timestamp', get_option("gmt_offset")) + $d;
update_post_meta($post->ID, '_expire', $expire);
*/
// 現在のローカルタイムスタンプ
$now = current_time('timestamp', get_option("gmt_offset"));
$args = array(
'post_type' => 'one_line_comment',
'taxonomy' => 'span',
'posts_per_page' => 5,
'order' => 'ASC',
'meta_key' => '_expire',
'meta_value' => $now,
'meta_compare' => '>',
);
$posts = get_posts($args);
foreach($posts as $post) {
setup_postdata($post);
// 必要な処理
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment