Skip Navigation

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

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

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 hace 5 años, 9 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Etiquetado: ,

Este tema contiene 6 respuestas, tiene 2 mensajes.

Última actualización por Edward Barker hace 5 años, 8 meses.

Asistido por: Luo Yang.

Autor
Mensajes
#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!

Los hilos nuevos creados por Luo Yang y vinculados a este se encuentran a continuación:

https://toolset.com/es/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!