No results found. Try again with different words?

Search must be at least 3 characters.

Display Posts Based on Last Modified Date in Post Grid

Sidebar Image

Did not find a solution? We are here to help you succeed.

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

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!

Was this article helpful?
Sidebar Image

Did not find a solution? We are here to help you succeed.

Related Docs

Join 1,653,898+ Happy Site Owners Using Astra

Whether you are a beginner, small business owner, or professional web developer, Astra provides all the tools you need to easily build your beautiful WordPress website.

REWIND

YEAR IN REVIEW

Download is Just A Click Away!

Membership Retention Checklist Download

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form
Scroll to Top
Now choose your preferred
page builder addon
Choose your preferred page builder addon

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Astra Theme - Modal Popup Form