[Plugin: Events Manager] Code for custom date range scope with WP_Query (4 posts)

  1. Miguel Peixe
    Posted 4 years ago #

    Hello everyone,

    As I said before in this topic, I was having trouble using '2012-02-01,2012-02-28' scope with WP_Query (I'm not using WP_Event class for particular reasons, as mentioned at the linked topic above).

    I realized that the code implemented at classes/em-object.php to handle this kind of scope wasn't implemented at classes/em-event-post.php. It checks for an array inside $scope and add the range conditional [classes/em-object.php line 199]. To make it work using WP_Query I adapted the code inside em-object.php to work inside em-event-post.php.

    The sample is here:
    http://pastebin.com/YwErsi76 (starting from line 157 and changing the first if to elseif)

    Now I'm able to use this query:

    $args = array( 'post_type' => 'event', 'scope' => array('2012-02-01','2012-02-28'));

    Please, feel free to adapt and comment.

  2. agelonwl
    Posted 4 years ago #

    thanks for sharing, however maybe you can try to use hooks/filters to make it update friendly.

  3. Marcus
    NetWebLogic Support
    Posted 4 years ago #

    you may want to check the dev version in the EM_Object function, I now have a build_wp_query_conditions function which is still experimental, but in theory you could create a WP_Query class and use the above to create the right query vars.

    I believe this already allows for what you added

    thanks for contributing!

  4. Marcus
    NetWebLogic Support
    Posted 4 years ago #

    btw, if you do play with it, pls let me know your findings, I haven't tried it yet...

Topic Closed

This topic has been closed to new replies.

About this Topic