Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Last active February 15, 2021 18:16
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 danielbachhuber/32f08fef5ab4c55a6d69f7bf22dbd7c2 to your computer and use it in GitHub Desktop.
Save danielbachhuber/32f08fef5ab4c55a6d69f7bf22dbd7c2 to your computer and use it in GitHub Desktop.
<?php
/**
* Uses the custom fields as the document's 'post_content'.
*/
add_action(
'solr_build_document',
function ( $doc, $post ) {
// Only override for this page template.
if ( 'template-page-builder.php' !== get_post_meta( $post->ID, '_wp_page_template', true ) ) {
return $doc;
}
$plugin_s4wp_settings = solr_options();
$index_custom_fields = apply_filters( 'solr_index_custom_fields', $plugin_s4wp_settings['s4wp_index_custom_fields'] );
$post_content = '';
foreach ( $index_custom_fields as $meta_key ) {
$post_content .= get_post_meta( $post->ID, $meta_key, true ) . PHP_EOL . PHP_EOL;
}
$doc->setField( 'post_content', strip_tags( $post_content ) );
return $doc;
},
10,
2
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment