Ii have problem with WP Query, can’t order by meta key
I use Event Manager plugin, and need query 4 post on my Homepage,
I need post only current and future events(posts) and sort by start date.
Here is my code
$time = date('Y-m-d');
$timeStro = strtotime($time);
$myNewQuery = new WP_query(
array(
'post_type' => 'event',
'featured' => 'yes',
'meta_key' => 'event_start_date',
'meta_type' => 'numeric',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'showposts' => 4,
'meta_query' => array(
array(
'key' => strtotime('_event_end_date'),
'value' => $timeStro,
'type' => 'numeric',
'compare' => '>='
)
)
));
Thanks you all! 🙂
At the end, we must hardcode and make our query from DB
<?php
global $wpdb;
$time = date('Y-m-d');
$events = $wpdb->get_results( "SELECT * FROM wp_em_events WHERE event_end_date >= '$time' ORDER BY event_start_date LIMIT 4");
foreach($events as $event) {
?>
<li>
<a href="<?php echo get_permalink($event->post_id); ?>">
<div class="div-calendar-entry">
<p class="calendar-title"><?php echo $event->event_name; ?></p>
</div>
</a>
</li>
<?php } ?>
please use
in place-of
I ended up with the following: