-
-
Save sachyya/18c1ef74e691fc4729050d57f984497e to your computer and use it in GitHub Desktop.
Add ACF fields for indexing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Step 1 | |
// Adding the ACF field to schema to be indexed | |
function cm_typesense_add_acf_field_to_schema( $schema, $name ) { | |
if ( $name == 'post' ) { // change post to your schema name | |
$schema['fields'][] = [ 'name' => 'acf_field', 'type' => 'string' ]; // | |
} | |
return $schema; | |
} | |
add_filter( 'cm_typesense_schema', 'cm_typesense_add_acf_field_to_schema', 10, 2 ); | |
// Step 2 | |
// Formatting data for field | |
function cm_typesense_format_acf_field_data ( $formatted_data, $raw_data, $object_id, $schema_name ) { | |
if ( $schema_name == 'post' ) { // Change post to your schema name | |
$formatted_data['category'] = get_field( 'acf_field', $raw_data->ID ); | |
} | |
return $formatted_data; | |
} | |
add_filter( 'cm_typesense_data_before_entry', 'cm_typesense_format_acf_field_data', 10, 4 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment