How to list posts published after a certain date
Posts Table Pro comes with various built-in ways to choose which posts to include in the table. For example, you can list posts by category, tag, date published, and so on.
If you wanted to display the most recent 20 posts then you could sort the table by date and use the Post limit option to only show 20 posts in the table.
However, there is no built-in way to list all posts published after or before a specific date. The folllowing code snippet will allow you to do this:
add_filter( 'posts_table_query_args', function( $args, $posts_table ) { $args['date_query'] = array( array( 'after' => 'January 1st, 2023', 'before' => 'December 31st, 2023', 'inclusive' => true, ), ), return $args; }, 10, 2 );
You can delete the “after” or “before” line in the code above based on your needs. You should also change the date with the same format in the code.
Please note that these code snippets are aimed at developers. If you feel comfortable using them, our article on how to use code snippets can serve as a helpful guide. If you’re not sure how to use this code then you should ask your developer, or you can use our plugin customization service.