Skip to content

Instantly share code, notes, and snippets.

@sachyya
Created July 28, 2023 07:26
Show Gist options
  • Save sachyya/3be2d1e970684749a482320f6868fe89 to your computer and use it in GitHub Desktop.
Save sachyya/3be2d1e970684749a482320f6868fe89 to your computer and use it in GitHub Desktop.
Index multiple custom post types in one index
<?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