Title: Filter Popularpost query by custom date field
Last modified: May 29, 2020

---

# Filter Popularpost query by custom date field

 *  Resolved [Menzer](https://wordpress.org/support/users/menzer/)
 * (@menzer)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/filter-query-by-custom-field/)
 * Hi guys, I have been using this plugin for years and it is a fantastic plugin,
   keep up the great work, I’m throwing this out there to anyone who can help please.
 * I have my current query by custom post & taxonomy working fine (currently using
   a widget but I can switch to template tag if needed to filter the query further)
   but what I need to do is filter the current query so it only shows post based
   on a custom start date fild so only now and future post display, I have played
   with the template tag and pre_get_posts but not manage to get the output I need,
   any help would be appreciated.
 * Thanks
    -  This topic was modified 6 years, 3 months ago by [Menzer](https://wordpress.org/support/users/menzer/).

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

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/filter-query-by-custom-field/#post-12918373)
 * Hi [@menzer](https://wordpress.org/support/users/menzer/),
 * > I have been using this plugin for years and it is a fantastic plugin, keep 
   > up the great work
 * Thank you! Glad to know that the plugin has been helpful for you during all this
   time.
 * > (…) what I need to do is filter the current query so it only shows post based
   > on a custom start date fild so only now and future post display, I have played
   > with the template tag and pre_get_posts but not manage to get the output I 
   > need, any help would be appreciated.
 * Well, this is doable but will require a bit of effort and coding skills.
 * One possible solution would be to [create custom meta field(s) to store views data for your posts & pages (and custom post types)](https://wordpress.org/support/topic/how-to-sorting-a-custom-query-by-views-all-time-monthly-weekly-or-daily/),
   then use the use the [WP_Query](https://developer.wordpress.org/reference/classes/wp_query/)
   class with the [meta query parameter](https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parameters)
   to sort posts by views and filter by your custom date field.
 * For example (untested, you may need to tweak it a bit/fix it):
 *     ```
       $args = array(
           'post_type'  => 'post',
           'orderby' => 'meta_value', 
           'meta_key' => 'views_weekly',
           'meta_query' => array(
               array(
                   'key' => 'YOUR_DATE_FIELD_HERE',
                   'value' => date('Y-m-d'),
                   'compare' => '>='
               )
           ),
       );
       $query = new WP_Query($args);
       ```
   
 *  Thread Starter [Menzer](https://wordpress.org/support/users/menzer/)
 * (@menzer)
 * [6 years, 3 months ago](https://wordpress.org/support/topic/filter-query-by-custom-field/#post-12927255)
 * Hey Hector, thanks for getting back to me, really appreciate it, I will play 
   with your suggestions and see if I can sort it out!! 🙂 Wish me luck

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

The topic ‘Filter Popularpost query by custom date field’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-popular-posts/assets/icon-256x256.png?rev=1232659)
 * [WP Popular Posts](https://wordpress.org/plugins/wordpress-popular-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-popular-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-popular-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-popular-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-popular-posts/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Menzer](https://wordpress.org/support/users/menzer/)
 * Last activity: [6 years, 3 months ago](https://wordpress.org/support/topic/filter-query-by-custom-field/#post-12927255)
 * Status: resolved