Skip to content

Instantly share code, notes, and snippets.

@msaari
Created September 3, 2018 05:55
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/a8be590001ef26137fb9226414fb4c82 to your computer and use it in GitHub Desktop.
Save msaari/a8be590001ef26137fb9226414fb4c82 to your computer and use it in GitHub Desktop.
Index attachment titles for parent
<?php
// Add this function to your theme functions.php and reindex.
add_filter( 'relevanssi_content_to_index', 'rlv_index_attachment_names', 10, 2 );
function rlv_index_attachment_names( $content, $post_id ) {
$attachments = get_children(
array(
'post_parent' => $post_id,
'post_type' => 'attachment',
)
);
foreach ( $attachments as $attachment ) {
$content .= ' ' . $attachment->post_title;
}
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment