category name with hyphen | WordPress.org

[ad_1]

Not sure there’s going to be a way to get around that, to be honest. Also last I knew, taxonomy slugs weren’t supposed to have dashes, only underscores. Probably for situations like this.

I suspect your browser’s developer tool console is probably throwing a “category is not defined” error.

Yes, the error message is that “category is not defined”

It’s likely going to be better to rename the taxonomy to use an underscore instead of a dash, in this case. I doubt we’d be able to get around it any other way.

The taxonomy is from the Tutor LMS plugin. Can I rename with functions.php before sending to algolia?

I think you may be able to do this with this sample code.

function felipee_adjust_index_content( $shared_attributes, $post ) {

	$shared_attributes['taxonomies']['course_category'] = $shared_attributes['taxonomies']['course-category'];
	unset( $shared_attributes['taxonomies']['course-category'] );

	return $shared_attributes;
}
add_filter( 'algolia_searchable_post_shared_attributes', 'felipee_adjust_index_content', 10, 2 );

Basically set a different array index in the attributes and assign the original index content, before unsetting the original “bad” one with the dash.

I’m pretty certain this is for the instantsearch indexes. If you’re needing for autocomplete, then I think you’d want to change the filter to algolia_post_shared_attributes. Add this code and edit one of the posts, to test/confirm before doing any bulk work.

It worked! Thank you very much, Michael.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer