Querying by post category slug with core/query block markup

You should not modify the taxQuery value, or that it should always be in the form of {"<taxonomy>":[<term IDs>],"<taxonomy>":[<term IDs>],"<taxonomy>":[<term IDs>],...}.

But you can add custom arguments, so "categoryName":"news" is good.

And then you can use the query_loop_block_query_vars filter to add the category slug to the WP_Query arguments coming from the Query Loop block.

Here’s an example where I used tax_query ( and not category_name ):

// `categoryName` is not part of `$query` (because `categoryName` is a custom
// argument), but it is stored in the `$block->context['query']` array, which
// explains why we need the second parameter, i.e. `$block`.
function my_filter_query_loop_block_query_vars( $query, $block ) {
    if ( ! empty( $block->context['query']['categoryName'] ) ) {
        $tax_query = isset( $query['tax_query'] ) ? (array) $query['tax_query'] : array();

        $tax_query[] = array(
            'taxonomy' => 'category',
            'terms'    => $block->context['query']['categoryName'],
            'field'    => 'slug',
        );

        $tax_query['relation'] = 'OR';

        $query['tax_query'] = $tax_query;
    }

    return $query;
}
add_filter( 'query_loop_block_query_vars', 'my_filter_query_loop_block_query_vars', 10, 2 );

techhipbettruvabetnorabahisbahis forumutaraftarium24edusedueduedusedueduedueduseduedus