Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Last active February 15, 2021 18:16
Show Gist options
  • Save danielbachhuber/32f08fef5ab4c55a6d69f7bf22dbd7c2 to your computer and use it in GitHub Desktop.
Save danielbachhuber/32f08fef5ab4c55a6d69f7bf22dbd7c2 to your computer and use it in GitHub Desktop.

Revisions

  1. danielbachhuber revised this gist Feb 15, 2021. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions use-fields-for-post-content.php
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@
    '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;
    }
  2. danielbachhuber created this gist Feb 15, 2021.
    25 changes: 25 additions & 0 deletions use-fields-for-post-content.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    <?php

    /**
    * Uses the custom fields as the document's 'post_content'.
    */
    add_action(
    'solr_build_document',
    function ( $doc, $post ) {

    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
    );