Topic: Custom query: how to show future events only? | WP Masonry Layout

Custom query: how to show future events only?

Home Forums Pro Version Custom query: how to show future events only?

Tagged: 

This topic contains 5 replies, has 2 voices, and was last updated by  Masonry Guy 5 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #14633 Reply

    Ben De Troyer
    Participant

    Hi 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!

    #14683 Reply

    Masonry Guy
    Keymaster

    Hi 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

    #14804 Reply

    Ben De Troyer
    Participant

    Hello 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…

    #14808 Reply

    Masonry Guy
    Keymaster

    Hi 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 http://www.masonrylayout.com/rectify-my-problem/.

    please kindly keep this thread url as well.

    Thanks

    #14911 Reply

    Ben De Troyer
    Participant

    Hi Masonry Guy

    Did you receive the message I sent with the form at http://www.masonrylayout.com/rectify-my-problem/?

    Regards

    #14922 Reply

    Masonry Guy
    Keymaster

    Hi 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

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: Custom query: how to show future events only?
Your information: