Skip to content

Instantly share code, notes, and snippets.

@miya0001
Created November 19, 2011 03:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save miya0001/1378387 to your computer and use it in GitHub Desktop.
Save miya0001/1378387 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