Home › Forums › Pro Version › Custom query: how to show future events only?
Tagged: Custom Query
- This topic has 5 replies, 2 voices, and was last updated 4 years, 5 months ago by
Masonry Guy.
- AuthorPosts
- October 10, 2016 at 8:41 am #14633
Ben De Troyer
ParticipantHi there!
I use the wp masonry lay-out to display some events and I use following custom query:
orderby=eventstart&order=ASC
Now, I noticed this also shows past events in the list. How can I add a parameter that shows only future events?
Thanks!
October 12, 2016 at 1:53 pm #14683Masonry Guy
KeymasterHi Ben,
For that you need to write a complex query for it and need to use filter. It should be like this and you need to keep in your functions.php of your theme file.
add_filter('wmlp_query', 'my_custom_query_wmlp',10,2); function my_custom_query_wmlp($args, $shortcodeID){ if ($shortcodeID == 2){ //WHERE 2 should be replaced with your shortcode ID $today = date('Ymd'); $args['meta_key'] = 'eventstart'; $args['meta_query'] = array( array( 'key' => 'eventstart', 'value' => $today, 'compare' => '>=' ) ); $args['orderby'] => 'meta_value_num'; $args['order''] => 'ASC'; return $args; } }
Hope this helps. Also, please make sure your date is in YMD format.
Thanks
October 18, 2016 at 8:29 am #14804Ben De Troyer
ParticipantHello Masonry Guy
I tried your query, but it doesn’t work (even after I fixed the double ‘ in $args[‘order”]). It returns a blank page and the error Parse error: parse error in website/functions.php on line 380:
$args[‘orderby’] => ‘meta_value_num’;
Could this have something to do with the YMD format? Where do I change this? Because I’m using jMY in my website…
October 18, 2016 at 5:13 pm #14808Masonry Guy
KeymasterHi Ben,
Have you used the full code in your functions.php that i sent in above ?
If so and it is still not working, there might be some other issue and field name conflict. So to check this in details, please kindly send me your wp-admin details, url using our form at https://www.masonrylayout.com/rectify-my-problem/.
please kindly keep this thread url as well.
Thanks
October 24, 2016 at 1:56 pm #14911Ben De Troyer
ParticipantHi Masonry Guy
Did you receive the message I sent with the form at https://www.masonrylayout.com/rectify-my-problem/?
Regards
October 24, 2016 at 4:17 pm #14922Masonry Guy
KeymasterHi Ben,
Sorry for the delay in reply due to weekend. Ya i have got the details and i was working for it few hrs back. But couldn’t make it work. I am still trying with other solution.
Please allow me extra next 24 hrs.
Thanks
- AuthorPosts
- The forum ‘Pro Version’ is closed to new topics and replies.