facetwp_indexer_query_args
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)
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
$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
argument of the register_post_type() function must be set to false
. You can do this directly in the function’s arguments, or with a hook.
But you may want to keep a post type non-searchable, 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:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_indexer_query_args', function( $args ) { $args['post_type'][] = 'wprm_recipe'; return $args; });
Index attachments and draft, pending or private posts
By default, FacetWP only indexes, displays and filters “published” items, meaning posts that have their post_status
set to publish
.
This excludes attachments (like images, media, and PDFs), which are posts that have their post_status
automatically set to inherit
. It also excludes other possible post statuses, like draft
, pending
and private
.
To force FacetWP to index the attachment
post type for all facets, add the code following to your (child) theme’s functions.php, and then click the re-index button:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_indexer_query_args', function( $args ) { $args['post_status'] = [ 'publish', 'inherit' ]; return $args; });
To index published and pending posts, use the following:
How to use custom PHP code?
PHP code can be added to your (child) theme's functions.php file. Alternatively, you can use the Custom Hooks add-on, or a code snippets plugin. More info
add_filter( 'facetwp_indexer_query_args', function( $args ) { $args['post_status'] = [ 'publish', 'pending' ]; return $args; });
Note that indexing attachments (or other post statuses) is not enough to display them in your post listing. See this tutorial for more info about filtering and displaying attachments, and/or draft, pending, or private posts.
If you are using SearchWP, see our SearchWP page for additional options to search within attachments/PDFs.