searchwp\post__in
Since: 4.0.0
Table of Contents
Control a global limiter for \WP_Post
IDs that are considered during indexing and searching.
Parameters
Type | Parameter | Default | Since |
---|---|---|---|
Integer[] | $ids |
[] |
4.0.0 |
Examples
All hooks should be added to your custom SearchWP Customizations Plugin.
Limit the search pool to Uncategorized Posts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Limit the search pool to Uncategorized Posts in SearchWP. | |
add_filter( 'searchwp\post__in', function( $ids, $args ) { | |
return array_unique( array_merge( $ids, get_posts( [ | |
'fields' => 'ids', | |
'nopaging' => true, | |
'post_type' => 'post', | |
'tax_query' => [ [ | |
'taxonomy' => 'category', | |
'field' => 'name', | |
'terms' => 'Uncategorized', | |
] ] | |
] ) ) ); | |
}, 20, 2 ); |