I’ve read that thread and a couple more on the same issue, but I haven’t been able to figure out a solution by reading them.
I think my problem is more simple that the one in that thread. I just want to query the events with scope=future, but the query comes with every event.
What confuses me a lot is that this is not a complicated query, I don’t know if I am missing something too obvious here in my query.
sorry, I’m afraid that I can’t help you with custom codes.
Well, is not THAT custom, I just want to query the events with scope = future using WP_Query
Is it that difficult or weird what I’m trying to do?
What I need to do is this:
$EM_Events = EM_Events::get( array(‘scope’=>’future’) );
But using WP_Query
Any help?
Let me up this to see if I can get some help.
No luck; still stuck trying to query the events with scope = future using WP_Query
maybe this snippet can give you some idea –
function my_em_wp_query(){
$args = array(
'post_type' => 'event',
'posts_per_page' => 100,
'meta_query' => array( 'key' => '_start_ts', 'value' => current_time('timestamp'), 'compare' => '>=', 'type'=>'numeric' ),
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_key' => '_start_ts',
'meta_value' => current_time('timestamp'),
'meta_value_num' => current_time('timestamp'),
'meta_compare' => '>='
);
// The Query
$query = new WP_Query( $args );
// The Loop
while($query->have_posts()):
$query->next_post();
$id = $query->post->ID;
echo '<li>';
echo get_the_title($id);
echo ' - '. get_post_meta($id, '_event_start_date', true);
echo '</li>';
endwhile;
// Reset Post Data
wp_reset_postdata();
}
add_shortcode('em_wp_query','my_em_wp_query');
Tnx for the snippet @agelonwi, helped me on my way. Only thing is that a meta_query needs to have a double array apparently. Example from: http://codex.wordpress.org/Class_Reference/WP_Query
$args = array(
'post_type' => 'product',
'meta_query' => array(
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'NOT LIKE'
)
)
);
$query = new WP_Query( $args );
So the resulting query arguments would be something like:
$args = array(
'post_type' => 'event',
'posts_per_page' => '4',
'meta_query' => array(
array(
'key' => '_start_ts',
'value' => current_time('timestamp'),
'compare' => '>=',
'type'=>'numeric'
)
)
);