fork download
  1. <?php
  2.  
  3. //
  4. // WordPress WP_Query example how to order by 1 single date&time field
  5. // BUT sort by DATE DESC
  6. // and by TIME ASC
  7. //
  8.  
  9. $events = new WP_Query([
  10. // ... some other query settings of yours
  11.  
  12. 'meta_query' => [
  13. 'relation' => 'AND',
  14. 'date_meta' => [
  15. 'key' => 'date_and_time',
  16. 'value' => wp_date('Y-m-d'),
  17. 'compare' => '>=',
  18. 'type' => 'DATE',
  19. ],
  20. 'time_meta' => [
  21. 'key' => 'date_and_time',
  22. 'compare' => 'EXISTS', # we don't actually want any restriction around time
  23. 'type' => 'TIME',
  24. ],
  25. ],
  26. 'orderby' => [
  27. 'date_meta' => 'DESC',
  28. 'time_meta' => 'ASC',
  29. ],
  30. // order not needed for complex orderby
  31. ]);
  32.  
Runtime error #stdin #stdout #stderr 0.02s 25772KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Uncaught Error: Class 'WP_Query' not found in /home/BK5aLD/prog.php:9
Stack trace:
#0 {main}
  thrown in /home/BK5aLD/prog.php on line 9