How to add custom fields to the Schema
-
Hello!
I’m trying to add custom meta fields to the index. But as soon as I add a custom field to the ‘cm_typesense_schema’ filter, the index always returns empty. Happens with the custom post types and default posts.
Here is my code for the schema:
/*** 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.
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘How to add custom fields to the Schema’ is closed to new replies.