Issue with Adding Custom Meta Fields to Typesense Index in WordPress
TLDR Svitlana experienced errors when adding custom meta fields to Typesense index for WordPress. Digamber advised ensuring image URLs or empty strings are being sent to the index.
May 12, 2022 (20 months ago)
Svitlana
01:10 PMHere 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.
Jason
01:10 PMDigamber
03:40 PMAlso - please turn on debug log and check the logs it should provide more insight,
Typesense
Indexed 3011 threads (79% resolved)
Similar Threads
Issues with Schema Creation and Nested Fields
Sean encountered a problem with schema creation involving auto nested fields. Kishore Nallan suggested checking the API response for errors and adding problematic fields to the schema as optional. Sean confirmed the advice.
Sorting Results in Typesense and Handling Errors
Ramees asks about sorting results by distance in Typesense, entering a list of strings as a field, and resolving an error with `fields` format. Kishore Nallan assists with these issues and advises on storing timestamps and proper authentication.
Debugging & Encoding Issue with Typesense and PHP
Digamber had an issue displaying "R&B" after adding as a facet. Kishore Nallan suggested the PHP client might be encoding the value. After some discussion, Digamber concluded that WordPress was the cause, encoding categories into HTML entities.