Skip Navigation

[Resolved] Best way to display posts from last 30 days

This thread is resolved. Here is a description of the problem and solution.

Problem:

I'm just wondering whats the best way display posts that are created within the last 31 days, 182 days and 365 days.

Solution:

You can try custom PHP codes, for example:

https://toolset.com/forums/topic/best-way-to-display-posts-from-last-30-days/#post-1206717

Relevant Documentation:

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by Edward Barker 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1206572
Screenshot 2019-02-26 at 20.45.06.png

Hi There,

I'm just wondering whats the best way display posts that are created within the last 31 days, 182 days and 365 days.

I've attached a picture of the filter I'm currently applying but it doesn't return anything ..... however if I set it to 26 or less posts start to appear (my post dates range from 6/2/19 to 25/2/19). But surely increasing the number higher that 26 should still return the same results?

There seems to potentially be a solution here but I don't quite know how I'd apply it to my site - what slugs need to go where etc.

https://toolset.com/forums/topic/between-date-filter-not-working/

Many Thanks
Ed

#1206717

Hello,

In your case, you don't need to change any slug, for example, you can modify the PHP codes as below:

function tssupp_date_filter( $query_args, $view_settings, $view_id ){
 
    if ( 123 == $view_id ) { // Edit View ID
        $query_args['date_query'] = array( 
            array(
                'column'    =>   'post_date_gmt',
                'after'     =>   '31 days ago'
            )
        );
    }
 
    return $query_args;
}
add_filter( 'wpv_filter_query', 'tssupp_date_filter', 101, 3 );

Please replace 123 with your view's ID.

#1206726

Brilliant.

Ok last bit then because I'm being thick. I can find the view slug (monthly-ebe-feedback) but where do I find the view ID?

Ed

#1206739

You can get the Views ID in view's list:
Dashboard-> Toolset-> Views, column "ID"

#1212154

That's great, really simple fix.

If I wanted to apply it to a custom date field in a post type (slug - date-of-review , post type - reviews) how would I go about doing that?

Many thanks as always!

New threads created by Luo Yang and linked to this one are listed below:

https://toolset.com/forums/topic/display-posts-from-last-30-days-on-custom-date-field/

#1212370

I assume the original question of this thread has been resolved, for other new questions, please check the new thread here:
https://toolset.com/forums/topic/display-posts-from-last-30-days-on-custom-date-field/

#1222508

My issue is resolved now. Thank you!