Skip to main content

Query Filters

This page documents filters for modifying query arguments before a Loop executes.

FilterDescription
unblock/query/post_argsPost query arguments
unblock/query/term_argsTerm query arguments
unblock/query/user_argsUser query arguments
unblock/query/item_argsItems array before iteration

query/post_args

Filter WP_Query arguments before executing a post query.

apply_filters( 'unblock/query/post_args', array $args, string $id );
ParameterTypeDescription
$argsarrayWP_Query arguments
$idstringQuery identifier (block name or uid, empty string if unset)

Example: Limit Featured Posts

add_filter( 'unblock/query/post_args', function ( $args, $id ) {

if ( 'featured' === $id ) {
$args['posts_per_page'] = 3;
}

return $args;

}, 10, 2 );

Example: Exclude Current Post

add_filter( 'unblock/query/post_args', function ( $args, $id ) {

if ( 'related' === $id ) {
$args['post__not_in'] = [ get_the_ID() ];
}

return $args;

}, 10, 2 );

query/term_args

Filter WP_Term_Query arguments before executing a term query.

apply_filters( 'unblock/query/term_args', array $args, string $id );
ParameterTypeDescription
$argsarrayWP_Term_Query arguments
$idstringQuery identifier (block name or uid, empty string if unset)

Example: Hide Empty Terms

add_filter( 'unblock/query/term_args', function ( $args, $id ) {

$args['hide_empty'] = true;

return $args;

}, 10, 2 );

query/user_args

Filter WP_User_Query arguments before executing a user query.

apply_filters( 'unblock/query/user_args', array $args, string $id );
ParameterTypeDescription
$argsarrayWP_User_Query arguments
$idstringQuery identifier (block name or uid, empty string if unset)

Example: Order by Registration Date

add_filter( 'unblock/query/user_args', function ( $args, $id ) {

if ( 'team' === $id ) {
$args['orderby'] = 'registered';
$args['order'] = 'ASC';
}

return $args;

}, 10, 2 );

query/item_args

Filter the items array before iteration in an items query.

apply_filters( 'unblock/query/item_args', array $args, string $id );
ParameterTypeDescription
$argsarrayData array to iterate
$idstringQuery identifier (block name or uid, empty string if unset)

Example: Filter Items by Condition

add_filter( 'unblock/query/item_args', function ( $args, $id ) {

if ( 'gallery' === $id ) {
$args = array_filter( $args, function ( $item ) {
return ! empty( $item['visible'] );
} );
}

return $args;

}, 10, 2 );
Common mistake

The $id parameter is only set when you assign a query name to the Loop block. Without it, $id is an empty string — your condition will never match. Always assign a name to loops you want to target with filters.

Next steps

  • Loop — loop overview and data sources
  • Data filters — filter provider data and meta values
  • Actions — lifecycle and form action hooks