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. You can refer to our article for guidance on how to use code snippets. 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 you can use our plugin customization service.
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"]