0

I am trying to show upcoming events. I have created a custom post type "event" in wordpress. and by using ACF plugin i have created date field for every event. now i want to show upcoming events. Here is my code. it is not working

$today = date('D. j. M');
$customEvent = new Wp_Query(array(
    'posts_per_page' => 4,
    'post_type' => 'event',
    'meta_key' => 'start_date',
    'orderby' => 'meta_value_num',
    'order' => 'ASC',
    'meta_value' => date('D. j. M'),
    'compare' => '>=',
));
1
  • It sounds like you need to look into how the date values are being saved. If you have an option to save them as a Unix timestamp, that will likely give you the best comparison, as it will be a matter of comparing one number to another. It looks like your current code is trying to compare textual representations, which is not an easy comparison and is probably why you're not getting results.
    – WebElaine
    Aug 8 at 14:01

1 Answer 1

0
  1. check phpmyadmin or similar database tool to see how your start_date is being stored.
  2. When you find how the variable is being stored, query all events and get their start_datess, convert each one into a date object and compare it to today's date and only display events whose start_date is after today. (https://www.geeksforgeeks.org/comparing-two-dates-in-php/)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.