-
Dan Hotchkiss
It is possible to exclude posts from a query block that are older than a fixed date. Is it possible to exclude posts that are more than a certain number of days old?
Thanks,
Dan -
Hi Dan,
Try this:
1. Add a CSS class to the query block, eg.
posts-in-30-days.
Adding CSS class(es): https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/2. Add this PHP code, change 30 to other values you want.
add_filter( 'generateblocks_query_wp_query_args', function( $query_args, $attributes ) { if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'posts-in-30-days' ) !== false && ! is_admin() ) { // Set the date query to only include posts published within the last 30 days $query_args['date_query'] = array( array( 'after' => '30 days ago', ), ); } return $query_args; }, 10, 2 );Adding PHP: https://docs.generatepress.com/article/adding-php/
-
Dan Hotchkiss
Thank you, Ying. This will be a very useful trick–and I hope a prototype for a future feature.
Dan
-
You are welcome 🙂
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.