This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Category Name Filter Not Working

#6611
Ernest MarcinkoErnest Marcinko
Keymaster

Hi!

I think the problem here might be that you are using a custom taxonomy.

I suppose you are talking about this example: https://wp-dreams.com/knowledge-base/showing-the-category-titles-in-the-result-title/

This only works with post categories, because for other taxonomy terms a different wordpress function is used. I’ve made a quick modification, that should get the terms of the specified taxonomy:

[php]
add_filter( ‘asp_pagepost_results’, ‘asp_add_term_titles’, 1, 1 );

function asp_add_term_titles( $pageposts ) {
foreach ($pageposts as $k=>$v) {

// Edit this to the taxonomy you are using
$taxonomy = "mytaxonomy";

// Get the taxonomy terms
$post_terms = wp_get_post_terms( $pageposts[$k]->id, $taxonomy );
$terms = "";

// Concatenate category names to the $cats variable
foreach($post_terms as $c){
$term = get_term( $c, $taxonomy );
$terms = " ".$term->name;
}

// Modify the post title
$pageposts[$k]->title .= " ".$terms;
}

return $pageposts;
}
[/php]

Don’t forget to change the $taxonomy variable to the taxonomy you are using with the custom post type.