searchwp\post__not_in
Desde: 4.0.0
Tabla de contenidos
Controla una exclusión global de IDs de \WP_Post a tener en cuenta durante la indexación y la búsqueda.
Parámetros
| Tipo | Parámetro | Predeterminado | Desde |
|---|---|---|---|
| Integer[] | $ids |
[] |
4.0.0 |
Ejemplos
All hooks should be added to your custom SearchWP Customizations Plugin.
Ignora siempre la publicación 732 y la página 98
This file contains hidden or 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 | |
| // Always ignore Post 732 and Page 98 in SearchWP. | |
| add_filter( 'searchwp\post__not_in', function( $ids ) { | |
| return array_merge( $ids, [ 732, 98 ] ); | |
| }, 20, 2 ); |
Excluir publicación(es) con un valor de clave meta
Indica a SearchWP que ignore cualquier publicación con un valor de clave meta my_meta_key de ‘meta value 1’, ‘meta value 2’ o ‘meta value 3’
This file contains hidden or 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 | |
| // Tell SearchWP to exclude any posts with a my_meta_key | |
| // value of 'meta value 1', 'meta value 2', or 'meta value 3'. | |
| add_filter( 'searchwp\post__not_in', function( $ids ) { | |
| return array_unique( array_merge( $ids, get_posts( [ | |
| 'fields' => 'ids', | |
| 'nopaging' => true, | |
| 'post_type' => 'any', | |
| 'meta_query' => [ [ | |
| 'key' => 'my_meta_key', | |
| 'value' => [ 'meta value 1', 'meta value 2', 'meta value 3', ], | |
| 'compare' => 'IN', | |
| ], ], | |
| ] ) ) ); | |
| }, 20, 2 ); |

