// facetwp_query_args

Overview

This filter lets you override the Query Arguments field from FacetWP 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_Facet class and all properties (see /includes/class-facet.php)

// Based on WP_Query. See the "Query Arguments" box in your shortcode template
$query_args = array(
    '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 );