There was a view that was showing the last 3 days of posts published by category.
MAs today displays No items found but have been published normally.
I wanted to know the reason for this.
Please see a view here. hidden link
I'm trying to make these two date options.
I need to display the last 3 published posts in a category.
I need to display the last 3 published posts in a category.
This is a bit different from posts in the last 3 days. If you need to display the last 3 published posts, do not use a date filter. Sort the View by post date, and set a limit of 3 posts.
There was a view that was showing the last 3 days of posts published by category.
If you want to show posts from the latest 3 days, it's not possible to set up that type of filter in wp-admin. Instead, I can provide a custom code snippet that will help. Please remove all date filters from the View in wp-admin and add this code to your child theme's functions.php file, or create a new code snippet in Toolset > Settings > Custom Code:
function tssupp_recent_3_days($view_args, $view_settings, $view_id)
{
$view_ids = array( 123 ); // Edit for View IDs to apply to
if ( in_array($view_id, $view_ids) ) {
$view_args['date_query'] = array(
array(
'column' => 'post_date_gmt',
'after' => '3 days ago'
)
);
}
return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_recent_3_days', 101, 3);
Replace 123 with the numeric ID of this View to apply the new custom code date filter.
Yes I need to display published posts from the last 3 days of a category.
Should I make this code in all Views? because I need to create a view for each category.
Should I make this code in all Views?
You can add multiple View IDs like this:
$view_ids = array( 123, 456, 789 ); // Edit for View IDs to apply to
The code will apply to all the Views you list in this array.
because I need to create a view for each category.
Check out this documentation for passing arguments into Views. It might be more practical to use one View and pass the category information into that View using a shortcode attribute: https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/
Let me know if you have questions about that.