-
-
Save searchwpgists/df1f4721da516ef76f9386d778945f43 to your computer and use it in GitHub Desktop.
Update media attachment results to link to their parent post
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_live_search_results_entry_data', function( $data, $result ) { | |
| if ( $result instanceof \WP_Post && $result->post_type === 'attachment' ) { | |
| $parent_id = wp_get_post_parent_id( $result->ID ); | |
| if ( $parent_id ) { | |
| $data['permalink'] = get_permalink( $parent_id ); | |
| } | |
| } | |
| return $data; | |
| }, 20, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment