---
title: "Custom Queries for the Posts Block (Filter)"
source: "https://docs.nexcess.com/software/kadence/blocks/custom-queries-for-posts-block/"
description: "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 the…"
vertical: "Software"
area: "Kadence Blocks"
date: "2025-10-10"
last_modified: "2026-07-02"
---

# Custom Queries for the Posts Block (Filter)

The [Posts](https://docs.nexcess.com/software/kadence/posts-block/) 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](https://developer.wordpress.org/reference/classes/wp_query/) directly. You can add **PHP** **code** to your site using a plugin like [Code Snippets](https://docs.nexcess.com/software/kadence/blocks/add-custom-filter-or-function-with-code-snippets/) or your [child theme’s](https://docs.nexcess.com/software/kadence/what-is-child-theme-do-i-need-one/) `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

```php
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 (`post` and `SECONDARY_POST_TYPE`).
- Orders posts by publish date, newest first.

Example 2: Show Only Posts with a Populated Custom Field

```php
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)](https://docs.nexcess.com/software/kadence/blocks/custom-queries-advanced-query-loop/)** 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.
