The Posts block provides settings to display posts in a grid layout. However, sometimes you need to alter the query beyond the block’s built-in settings. In these cases, you can add a code snippet to modify the WordPress Query object directly. You can add PHP code to your site using a plugin like Code Snippets or your child theme’s functions.php file.
If you want to modify the query arguments, you can make use of kadence_blocks_posts_query_args filter.
Example 1: Query Multiple Post Types
add_filter( 'kadence_blocks_posts_query_args', function( $args ) {
if ( get_the_ID() === PAGE_ID ) {
$args['post_type'] = array( 'post', 'SECONDARY_POST_TYPE' );
// Order posts by publish date
$args['orderby'] = 'date';
$args['order'] = 'DESC';
}
return $args;
}, 10, 1 );
- Target Posts Block inside page with ID equals to
PAGE_ID - Queries multiple post types (
postandSECONDARY_POST_TYPE). - Orders posts by publish date, newest first.
Example 2: Show Only Posts with a Populated Custom Field
add_filter( 'kadence_blocks_posts_query_args', function( $args ) {
// Target Posts block on a specific page
if ( get_the_ID() === PAGE_ID ) {
// Specify the post type(s) you want to query
$args['post_type'] = 'post';
// Only show posts where a specific custom field exists
$args['meta_query'] = array(
array(
'key' => 'YOUR_CUSTOM_FIELD', // Replace with your field name
'compare' => 'EXISTS',
),
);
// Order posts by publish date
$args['orderby'] = 'date';
$args['order'] = 'DESC';
}
return $args;
}, 10, 1 );
- Target Posts Block inside page with ID equals to
PAGE_ID - Filters posts to include only those where the custom field has a value.
- Orders posts by publish date, newest first.
Explore More Examples
Even though the Query Loop (Advanced) Block and the Posts Block use different filters and methods for accessing the current block, the Custom Queries for the Advanced Query Loop Block (Filter) documentation provides many examples of the WordPress Query object being used logically. While these examples cannot be copied and pasted directly, they can be adapted for use with the Posts block.


