Created
October 28, 2022 08:19
-
-
Save msaari/21dffa784b51053356074d79ee390070 to your computer and use it in GitHub Desktop.
Indexing attached image titles for the parent post
This file contains 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 this to theme functions.php or in a code snippet. Then rebuild the index. | |
add_filter( 'relevanssi_content_to_index', 'rlv_add_image_titles', 10, 2 ); | |
function rlv_add_image_titles( $content, $post ) { | |
global $wpdb; | |
$results = $wpdb->get_col( | |
$wpdb->prepare( | |
"SELECT post_title FROM $wpdb->posts WHERE post_parent = %d", | |
$post->ID | |
) | |
); | |
foreach ( $results as $title ) { | |
$content .= " $title"; | |
} | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment