Skip to content

Instantly share code, notes, and snippets.

@msaari
Created October 28, 2022 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msaari/21dffa784b51053356074d79ee390070 to your computer and use it in GitHub Desktop.
Save msaari/21dffa784b51053356074d79ee390070 to your computer and use it in GitHub Desktop.
Indexing attached image titles for the parent post
<?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