1. Home
  2. Knowledge Base
  3. Posts Table Pro
  4. Advanced Usage

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 should paste this code in the functions.php file of your theme or child theme. 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.

If you’re not sure how to use this code then you should ask your developer, or post a job on Codeable to find a WordPress expert who can do it for you.

We've partnered with Codeable to provide our customers with expert help if required.

Related Articles

If searching the knowledge base hasn't answered your question, please contact support.