Hi! We are using Search with Typesense for WordPre...
# community-help
s
Hi! We are using Search with Typesense for WordPress and 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:
Copy code
/*** 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.
j
@Digamber Pradhan ^
d
Hi @Svitlana Sukhoveiko - make sure you are either sending an empty string or an actual image url to the index otherwise it fails. Also - please turn on debug log and check the logs it should provide more insight,