• Resolved rEaS

    (@reas)


    Hey, great plugin. Coming from a Drupal background, this has been a lifesaver. I have done everything I need with the plugin with one exception. I am trying to filter the view (oops, query) to just a set of specific dates. I want it to show posts older than 5 days ago but newer than 60 days ago. I tried playing with the meta_value, but I know that date is not in fact a meta value. Can anyone help me with this?

    Also not sure if the date can be restricted through the shortcode.. a.k.a. something like this [query slug=”homepage-most-popular” args=”start_date=5&end_date=60″], obviously not that but you get the idea..

    I’d be more than happy to export the query as well if that helps in any way. I’ll also be more than happy to buy someone a beer if they help me do this quickly. Thanks in advance!

    https://ww.wp.xz.cn/plugins/query-wrangler/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Hi rEaS,

    There isn’t a good way to do this with the args in shortcodes. What you need is a date_query, and the shortcode args can’t handle array notation. http://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Date_Parameters .

    There is a bug in the current release, or else you could handle this with a custom hook. I’ll try to push out a simple bug-fix-only release this evening. Then I’ll respond here with how to use the hook to achieve what you need.

    Sorry for the issues, more to come this evening.

    Thread Starter rEaS

    (@reas)

    Oh my god, thank you so much dude! I’ll be eagerly waiting for it!

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Hi rEaS,

    I’ve fixed the bug that was preventing the custom hooks from working correctly in version 1.5.25.

    I think this code will accomplish your date_query. You’ll need to put it in your theme’s function.php or a custom plugin.

    // custom hook into query-wrangler before the query is executed
    add_filter( 'qw_pre_query', 'my_qw_pre_query_filter', 10, 2 );
    
    // my custom hook callback
    function my_qw_pre_query_filter( $args, $options ){
    
      // only alter the targeted query
      if ( 'homepage-most-popular' == $options['meta']['slug'] ){
        $args['date_query'] = array(
          'before' => '5 days ago',
          'after' => '60 days ago',
        );
      }
    
      return $args;
    }

    In the future, I hope to have date_query as part of the UI. In the meantime, for more options on the date query, check the codex: http://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Date_Parameters .

    Let me know how this turns out!

    Thanks,
    Jonathan

    Thread Starter rEaS

    (@reas)

    ok let me try it, where do i get the latest code and whats the best way of manually updating a plugin in wordpress.. just copy over the files?

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Visit your Updates page ( /wp-admin/update-core.php ). It will detect there is an update and let you perform the update with a click.

    If it doesn’t list Query Wrangler there, click on “Check Again” button at the top. If it still doesn’t show up, give it 20 minutes and try again. Sometimes I have issue with very-recent updates.

    Thread Starter rEaS

    (@reas)

    holy cow! this worked great! but great..! thank you very much, anyone needing to filter a query by date, just use that filter and play with the dates/days.

    jonathan thank you so much for your help! im sending some cash your way for your help tomorrow when i get in the office!

    thanks again!

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Nice. Glad to help!

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Date Filter’ is closed to new replies.