Support » Fixing WordPress » Show Posts By Custom Date After Today

  • Resolved zaydB

    (@zaydb)


    Hey Guys,

    So Im working on showing posts based on a custom field date set for each post. The custom date is in the format (YYYYMMDD) e.g. 20160105. Ive gotten close but for some reason I can only get the events with the dates on the day to display rather than that and future date. Here is my code:

    $args = array('post_type' => 'ts_post',
    					'numberposts' => '7',
    					'meta_key' => 'CloseDate',
    					'post_status' => 'publish',
    					'orderby' => 'meta_value',
    					'order' => 'ASC',
    					'meta_query' => array(
    										array('value' => $dateToday,
    											  'comapre' => '>=',
    											  'type' => 'DATE')),);

    $dateToday is set as date('Ymd')
    Thanks

Viewing 1 replies (of 1 total)
  • Thread Starter zaydB

    (@zaydb)

    Solved it,
    So the problem with dates, especially custom ones, is that they’re stored as strings. Even if we set them in the format YYYYMMDD we won’t be able to compare the dates easily unless they’re set as YYYY-MM-DD. Once the dates are set this way they can be compared to a regular date, so todays date will need to be set this way. $dateToday = date('Y-m-d');

Viewing 1 replies (of 1 total)
  • The topic ‘Show Posts By Custom Date After Today’ is closed to new replies.