searchwp\results\entry\data
Seit: 4.0.0
Dieser Filter-Hook ermöglicht die Anpassung der Ausgabedaten für jeden SearchWP-Ergebnis-Eintrag, bevor er an die SearchWP-Vorlage übergeben wird. Er kann verwendet werden, um den angezeigten Titel, Permalink, das Bild oder den Inhalt zu ändern, sowie das Markup für bestimmte Objekttypen wie Beiträge, Taxonomie-Begriffe oder Benutzer anzupassen.
Parameter
| Typ | Parameter | Standard | Seit | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Array |
$data
|
4.0.0 |
||||||||||||||||||||||
| Objekt | $result |
Das SearchWP-Ergebnis-Eintrags-Objekt | 4.0.0 |
|||||||||||||||||||||
Beispiele
All hooks should be added to your custom SearchWP Customizations Plugin.
Fügen Sie benutzerdefinierten Inhalt für einen bestimmten Beitragstyp hinzu.
| <?php | |
| // Customize SearchWP result entry data for the SearchWP template. | |
| add_filter( 'searchwp\results\entry\data', function( $data, $result ) { | |
| if ( $result instanceof \WP_Post && $result->post_type === 'product' ) { | |
| $data['content'] .= '<p>Free delivery available!</p>'; | |
| } | |
| return $data; | |
| }, 20, 2 ); |
Passen Sie das Bild für Taxonomie-Begriff-Ergebnisse an
| <?php | |
| add_filter( 'searchwp\results\entry\data', function( $data, $result ) { | |
| // Check if the result is a taxonomy term. | |
| if ( $result instanceof \WP_Term ) { | |
| // Replace default image HTML with a placeholder. | |
| $data['image_html'] = '<img src="http://place-hold.it/500x500" />'; | |
| } | |
| return $data; | |
| }, 20, 2 ); |
Fügen Sie eine Beschriftung zu Benutzerergebnissen hinzu
| <?php | |
| add_filter( 'searchwp\results\entry\data', function( $data, $result ) { | |
| if ( $result instanceof \WP_User ) { | |
| $data['title'] .= ' (User Profile)'; | |
| } | |
| return $data; | |
| }, 20, 2 ); |

