Limit blog widget to only show posts from previous x days

Posted in: Newspaper
Post count: 3

Hi there

I am using a widget (tagdiv block 9) to return posts from a specific category.
Can I limit the widget to only show posts from the last 7 days?
Where can I make this change?
Thank you.. great theme!

Post count: 18283

Hello !

You can edit the widgets features using the tagDiv Composer. There you can limit your widget to display your most popular posts from the last 7 days like here: https://www.screencast.com/t/t2LnfUMF94. https://www.screencast.com/t/MWlWtFRbRDFr. Or you can display random posts from your last 7 days.

Thank you !

Post count: 3

Hi Vlad

Thank you for your reply. I do not want random posts or only popular posts.
I want to return ALL posts for the last 7 days sorted by date desc.

  • This reply was modified 7 years by 17seconds.
Post count: 18283

Hello !

Unfortunately at the moment there is no such feature to display all posts from the last 7 days.

Thank you !

Post count: 3

For anyone else looking for the same function, and I have seen quite a few people ask for this, here is how I solved it.
It is a workaround, and if someone can offer an improvement on this solution, please paste your code below.

Copy td_data_source.php from the parent theme and paste to:
/wp-content/themes/Newspaper-child/includes/wp_booster/td_data_source.php

I decided I am probably never going to use the Sort Alphabetically option for my td composer widgets. So, I updated the args array for Sort Alphabetical to suit my purposes.

Comment out the normal alphabetical order and use the new code below.

// case ‘alphabetical_order’:
// $wp_query_args[‘orderby’] = ‘title’;
// $wp_query_args[‘order’] = ‘ASC’;
// break;
case ‘alphabetical_order’: //Limit to last 10 days
$wp_query_args[‘date_query’] = array(
‘after’ => date(‘Y-m-d’, strtotime(‘-10 days’))
);
break;

@ the theme developers: Please can this can go on the wishlist and be included in a future version.
The amount of days should be a selectable field in the widget option.

Post count: 35449

Hi,

I will note your suggestion on our suggestions list for features.

Thank you!

Post count: 42

Thanks @17seconds 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic.