Svitlana Sukhoveiko
05/12/2022, 1:10 PM/*** Adds the post type book under available post_types ***/
function cm_typesense_add_available_post_types( $available_post_types ) {
$available_post_types['style_card'] = [ 'label' => 'Style Cards', 'value' => 'style_card' ];
return $available_post_types;
}
add_filter( 'cm_typesense_available_index_types', 'cm_typesense_add_available_post_types');
//only necessary if the default post schema is not necessary
function cm_typesense_style_card_schema( $schema, $name ) {
if ( $name == 'style_card' ) {
$schema = [
'name' => 'style_card',
'fields' => [
[ 'name' => 'post_title', 'type' => 'string' ],
[ 'name' => 'post_author', 'type' => 'string' ],
[ 'name' => 'post_date', 'type' => 'string' ],
[ 'name' => 'post_id', 'type' => 'string' ],
[ 'name' => 'post_thumbnail', 'type' => 'string' ],
[ 'name' => 'preview_image_url', 'type' => 'string' ], // custom field
],
];
}
return $schema;
}
add_filter( 'cm_typesense_schema', 'cm_typesense_add_style_card_schema', 10, 2 );
The index works if I remove [ 'name' => 'preview_image_url', 'type' => 'string' ]
and leave only the default WordPress fields.
Is there a way to add custom fields to the index and make it work? Thanks.Jason Bosco
05/12/2022, 1:10 PMDigamber Pradhan
05/12/2022, 3:40 PM