• Resolved Menzer

    (@menzer)


    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 4 years, 9 months ago by Menzer.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @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), then use the use the WP_Query class with the meta query parameter 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

    (@menzer)

    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.