Index a custom field with the values of an ACF repeated field

  • pseudo visitor
    # 1 year ago

    I defined a new custom field, which I’d like to index with the content of another ACF repeated field.

    Do you have some code for me to do that ?

    pseudo visitor
    # 1 year ago

    Here is a piece of code using WPSOLR’s filter

    Modify and copy the following  code into your theme’s functions.php, or in a new small plugin.

    use wpsolr\core\classes\WPSOLR_Events;
    use wpsolr\core\classes\WpSolrSchema;
    add_action( 'after_setup_theme', function () {
        add_filter( WPSOLR_Events::WPSOLR_FILTER_SOLARIUM_DOCUMENT_FOR_UPDATE, 'wpsolr_filter_solarium_document_for_update', 10, 5 );
    } );
     * @param array $document_for_update
     * @param $solr_indexing_options
     * @param $post
     * @param $attachment_body
     * @param WPSOLR_AbstractIndexClient $search_engine_client
     * @return array Document updated with fields
    function wpsolr_filter_solarium_document_for_update( array $document_for_update, $solr_indexing_options, $post, $attachment_body, WPSOLR_AbstractIndexClient $search_engine_client ) {
     $solr_dynamic_type = WpSolrSchema::_SOLR_DYNAMIC_TYPE_STRING; // Depends on the type selected on your field on screen 2.2
     $document_for_update[ 'my_field_name' . $solr_dynamic_type] = 'whatever';
     return $document_for_update;
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.