Skip Navigation

[Resolved] Show Last Post Publish by Category

This support ticket is created 4 years, 10 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by Christian Cox 4 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#1536303

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.

#1536361
databetewen.png
dataafterorequal.png

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.

#1536397

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.

#1536401

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.

#1536421

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.