Reputation: 655
I have a custom post type that displays depending on the custom post date (an event date) but now I cannot use the WordPress scheduling that is built in because posts show in relation to a custom meta date provided in the post.
Is there a way to add an argument into my array to check the post date so that it only displays the custom post if the post date has passed?
Here is my current code that does exactly as needed
$today = date('Y-m-d');
$args = array(
'post' => 'ID',
'post_type' => 'foodswaps',
'posts_per_page' => 3,
'meta_key' => '00.event-date',
'meta_value' => $today,
'meta_compare' => '>=',
'orderby' => 'meta_value',
'order' => 'ASC'
);
I have spent the last day looking for an answer but haven't found anything or any similar cases so any pointers and directional nudges would be appreciated!
Upvotes: 2
Views: 269
Reputation: 36
Try adding:
'post_status' => 'publish',
E.g.
$today = date('Y-m-d');
$args = array(
'post' => 'ID',
'post_type' => 'foodswaps',
'posts_per_page' => 3,
'post_status' => 'publish', // <-----------
'meta_key' => '00.event-date',
'meta_value' => $today,
'meta_compare' => '>=',
'orderby' => 'meta_value',
'order' => 'ASC'
);
That should then show only posts with the status published.
Upvotes: 2