In this guide, we will walk you through the steps to display posts in the Post Grid based on their last modified date.
This can be achieved by adding a custom filter to modify the post query arguments.
We have also included a reference code snippet and a short video tutorial to help you understand the process.
How to Display Posts Based on Last Modified Date in Post Grid
To ensure that the Post Grid shows posts sorted by the last modified date, you will need to add the following code snippet to your WordPress website:
add_filter( 'uagb_post_query_args_grid', function( $query_args, $attributes ) {
if ( 'custom-class' === $attributes['className'] ) {
$query_args['orderby'] = 'modified';
}
return $query_args;
}, 10, 2 );
This filter will modify the query arguments for the Post Grid and ensure that posts are displayed according to their last modification date when the custom-class class is applied to the Post Grid block.
For a clearer understanding of how this works, you can refer to the video embedded below. It walks through the process step-by-step, showing how the posts will appear based on the last modified date.
Once you’ve added the filter, check the front end of your website to ensure that the posts are displayed correctly. If the sorting is based on the last modified date, everything should be working as expected.
FAQ and Troubleshooting
Ensure that the custom-class is applied correctly to the Post Grid block. If you’re still having trouble, feel free to reach out to us for support.
Yes, you can modify ‘custom-class’ in the code to any class name you prefer. Just ensure that the class is applied to the correct block on the page.
If you don’t have a child theme installed, follow this guide: How to Install an Astra Child Theme.
Unsure how to add the code? Check out this guide: [How to Add Custom PHP Code in a Child Theme]
We hope this guide helps you to display posts based on last modified date in post grid. If you have any questions or need further assistance, feel free to leave a comment below!