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

List posts for current month only

The Posts Table Pro plugin comes with built-in options to list posts based on any combination of day, month, or year. If you’d like an automated way to list WordPress posts for the current month only, then we’ve provided a code snippet to help with this. For example, perhaps you have a news site and wish to display news articles from the current month on the homepage.

Please note that this is aimed at developers and if you don’t know how to use it, then you should ask a developer. If you don’t have one, then we’ve partnered with Codeable to provide customization services for our customers.

Need professional assistance?

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

Code snippet – list WordPress posts by current month

The following code snippet allows you to specify that you want to list only posts for the current month:

/**
* Allows specifying a value of 'current' for the month attribute in the [posts_table] shortcode.
*
* The value of 'current' will be converted to the number of the current month.
*
* @param array $args Shortcode attributes.
* @return array (Maybe) modified shortcode attributes.
*/
function barn2_allow_filtering_ptp_for_current_month( $args ) {
if ( ! empty( $args['month'] ) && 'current' === $args['month'] ) {
$args['month'] = date( 'n' );
}
return $args;
}
add_filter( 'shortcode_atts_posts_table', 'barn2_allow_filtering_ptp_for_current_month' );

In practice this looks like: [posts_table month="current"]

Still need help?

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

Related Articles