• Resolved felipee94

    (@felipee94)


    I’m having trouble getting the category name in hits. It’s because the category is hyphenated “taxonomies_hierarchical.course-category”. I think it’s being used with a math operator “-“. Anyone know how to solve this problem?

    Code:
    item: function (data) {
    if (data.post_date < Math.floor(d.setDate(d.getDate() – 7) / 1000)) {
    return (
    ‘<article> ‘ +
    data.taxonomies.course-category + ‘
    ‘ + ‘<p>’ + data._highlightResult.edd_price.value + ‘</p></div>’ +'<a class=”btn_button” href=”‘ +
    data.permalink + ‘” target=”_blank”>Details </article>’
    );
    }

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter felipee94

    (@felipee94)

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

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter felipee94

    (@felipee94)

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

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter felipee94

    (@felipee94)

    It worked! Thank you very much, Michael.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Welcome.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘category name with hyphen’ is closed to new replies.