LABE

[WP] Posts by post_meta from today to 1 month later

Feb 25th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1. /* https://ja.wordpress.org/support/topic/今日から1ヶ月以内のカスタム投稿を表示/ */
  2. $meta_key = 'hogehogedate';
  3. $today = date_i18n('Ymd');
  4. $ones_month = date('Ymd', strtotime('+1 month'));
  5. $mydata = get_posts( array(
  6.     'posts_per_page' => -1,
  7.     'post_type' => 'member-hogehoge',
  8.     'orderby' => 'meta_value',
  9.     'order' => 'ASC',
  10.     'meta_query' => array(
  11.         'relation' => 'AND',
  12.         array(
  13.            'key'     => $meta_key,
  14.            'value'   => $today,
  15.            'type'    => 'numeric',
  16.            'compare' => '>=',
  17.         ),
  18.         array(
  19.            'key'     => $meta_key,
  20.            'value'   => $ones_month,
  21.            'type'    => 'numeric',
  22.            'compare' => '<=',
  23.         ),
  24.     ),
  25. ) );
Advertisement
Add Comment
Please, Sign In to add comment