Created
July 28, 2023 07:26
-
-
Save sachyya/3be2d1e970684749a482320f6868fe89 to your computer and use it in GitHub Desktop.
Index multiple custom post types in one index
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 | |
add_filter( 'cm_typesense_schema', 'add_schema', 10, 2 ); | |
function add_schema( $schema, $name ) { | |
if ( $name === 'cpt_1' || $name = 'cpt_2' ) { | |
$schema['name'] = 'cpts-data'; | |
$schema['fields] = [ | |
[ 'name' => 'field_1', 'type' => 'string' ], | |
[ 'name' => 'field_2', 'type' => 'string' ], | |
]; | |
} | |
return $schema; | |
} | |
add_filter( 'cm_typesense_data_before_entry','document_format', 10, 4 ); | |
function document_format() { | |
if ( $schema_name == 'cpt_1' || $schema_name == 'cpt_2' ) { | |
$formatted_data['field_1'] = get_field1_funtion(); //Repalce this funciton with appropriate one | |
$formatted_data['field_2'] = get_field2_funtion(); | |
} | |
return $formatted_data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment