Overview

This filter lets you override the Query Arguments field from Listing Builder templates. The Query arguments array (used by WP_Query) tells WP which posts to retrieve from the database.

Parameters

  • $query_args | array | An associative array of query arguments (see below)
  • $class | object | The FacetWP_Renderer class (see /includes/class-renderer.php)
// Based on WP_Query. See the "Query Arguments" box in your shortcode template
$query_args = [
    'post_type' => 'post',
    'posts_per_page' => 15
];

Usage

// Sort by title if the shortcode template is named "bravo"
add_filter( 'facetwp_query_args', function( $query_args, $class ) {
    if ( 'bravo' == $class->ajax_params['template'] ) {
        $query_args['orderby'] = 'title';
        $query_args['order'] = 'asc';
    }
    return $query_args;
}, 10, 2 );

More examples

See also