searchwp\results\entry\data
4.0.0以降
このフィルターフックにより、各SearchWP結果エントリの出力データをSearchWPテンプレートに渡す前にカスタマイズできます。表示されるタイトル、パーマリンク、画像、またはコンテンツを変更したり、投稿、タクソノミターム、ユーザーなどの特定のオブジェクトタイプのマークアップを調整したりするために使用できます。
パラメータ
| タイプ | パラメータ | デフォルト | 提供開始 | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 配列 |
$data
|
4.0.0 |
||||||||||||||||||||||
| オブジェクト | $result |
SearchWPの結果エントリオブジェクト | 4.0.0 |
|||||||||||||||||||||
例
All hooks should be added to your custom SearchWP Customizations Plugin.
特定の投稿タイプにカスタムコンテンツを追加します。
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 | |
| // 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 ); |
タクソノミターム結果の画像をカスタマイズします
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 | |
| 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 ); |
ユーザー結果にラベルを追加します
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 | |
| add_filter( 'searchwp\results\entry\data', function( $data, $result ) { | |
| if ( $result instanceof \WP_User ) { | |
| $data['title'] .= ' (User Profile)'; | |
| } | |
| return $data; | |
| }, 20, 2 ); |

