• Hozefa Saleh

    (@hozefasmile)


    My Setup

    I have created a custom post type, and then created a archive template for that custom post type using site editor. In site editor I am using query loop block with “Inherit query from template” setting enabled to show all post on archive page.

    Problem (Issue)

    I want to filter the output of query loop block using a frontend form. For example I want to provide a search form, where someone search for words and that should filter the query loop block output and shows only those post which have that search query. for this I have crated this form on the archive template

    <form action="" method="get">
        <input type="text" name="s" id="search-query" placeholder="Enter keyword" />
        <input type="submit" value="Filter" />
    </form>

    and I am trying this code to modify the output based on the search query input.

    add_filter( 'query_loop_block_query_vars', 'uni_filter_query' );
    function uni_filter_query( $query_args ) {
        if ( isset( $_GET['s'] ) ) {
            $query_args['s'] = sanitize_text_field( $_GET['s'] );
        }
        return $query_args;
    }

    but this is not working and shows a blank result page instead of the filtered output. Am I not using ‘query_loop_block_query_vars’ properly? or is it not supporting it?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘‘query_loop_block_query_vars’ filter not helping me filter output’ is closed to new replies.