searchwp\post__not_in
Depuis : 4.0.0
Table des matières
Contrôlez une exclusion globale des identifiants \WP_Post à prendre en compte lors de l’indexation et de la recherche.
Paramètres
| Type | Paramètre | Défaut | Depuis |
|---|---|---|---|
| Tableau d'entiers | $ids |
[] |
4.0.0 |
Exemples
Tous les hooks doivent être ajoutés à votre plugin personnalisé SearchWP Customizations Plugin.
Toujours ignorer le Post 732 et la Page 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 ); |
Exclure les articles avec une valeur de clé méta
Demandez à SearchWP d’ignorer tout article ayant une valeur de clé méta my_meta_key de « meta value 1 », « meta value 2 » ou « 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 ); |

