DJP2019
DJP2019

Reputation: 69

Wordpress Query by custom date filed

Can someone show me how to do this, I have a query I'm using to display custom posts and using WP Facet for the query, by a custom field date, I got this far to order the posts by date in Ascending order, but the last thing I want to do is only show the posts that equal today's date or future dates;

I've tried a few things but no joy as of yet, thanks

<?php
return array(
'post_type' => 'event',
'post_status' => 'publish',
'posts_per_page' => 15,
'orderby'   => 'event_date',
'order' => 'ASC',
'sort_custom' => true,
'meta_query' => array(
  array(
    'key' => 'event_date',
  ),
  )

Upvotes: 0

Views: 43

Answers (1)

DJP2019
DJP2019

Reputation: 69

if this helps anyone - i worked it out:

<?php
 return array(
 'post_type' => 'event',
 'post_status' => 'publish',
 'meta_key' => 'event_date',
 'posts_per_page' => 15,
  'orderby'   => 'event_date',
  'order' => 'ASC',
  'sort_custom' => true,
  'meta_query'    => array(
   'relation'      => 'AND',
    array(
    'key' => 'event_date',
          'compare' => '>=',
          'value' => date("Y-m-d"),
          'type' => 'DATE'
    ),
    )
   );

Upvotes: 1

Related Questions