Overview

This filter lets you customize which posts get indexed. You have access to the Query Arguments array that gets passed to WP_Query.

Parameters

  • $args | array | An array of WP_Query arguments (see below)
$args = [
    'post_type'         => 'any',
    'post_status'       => 'publish',
    'posts_per_page'    => -1,
    'fields'            => 'ids',
];

Usage examples

Force indexing of non-searchable post types

FacetWP by default only indexes so-called “searchable” post types. To be “searchable”, the exclude_from_search parameter of the register_post_type() function must be set to false. The main reason for keeping a post type non-searchable is to prevent these posts from showing up in the front-end WordPress search results.

With this hook, it’s possible to force FacetWP to index and filter post types that are non-searchable.

For example, to force the wprm_recipe post type to be indexed, even though it’s non-searchable, add the following code to your (child) theme’s functions.php:

add_filter( 'facetwp_indexer_query_args', function( $args ) {
    $args['post_type'] = (array) get_post_types();
    $args['post_type'][] = 'wprm_recipe';
    return $args;
});

Index attachments

By default, FacetWP only indexes published items, which excludes attachments. To index attachments (media items) too, add the following code to your (child) theme’s functions.php:

add_filter( 'facetwp_indexer_query_args', function( $args ) {
    $args['post_status'] = [ 'publish', 'inherit' ];
    return $args;
});

More examples

See also