SearchWP Documentation

Visualizza la guida all'installazione, sfoglia la Knowledge Base, scopri i numerosi hook di SearchWP

searchwp\post__not_in

Da: 4.0.0

Controlla un'esclusione globale di ID di \WP_Post da considerare durante l'indicizzazione e la ricerca.

Parametri

Tipo Parametro Predefinito Da
Integer[] $ids [] 4.0.0

Esempi

All hooks should be added to your custom SearchWP Customizations Plugin.

Ignora sempre il post 732 e la pagina 98

<?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 );

Come usare questo codice

Escludi post con un valore di chiave meta

Indica a SearchWP di ignorare qualsiasi post con un valore della chiave meta my_meta_key di 'meta value 1', 'meta value 2' o 'meta value 3'

<?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 );

Come usare questo codice