Knowledge Base

Showing the category titles in the result title

in Ajax Search Pro Tips Tags: categoryfiltermodifytitle

For this task we are going to use a custom filtering function, which connects to one of the filters provided by ajax search pro.

Put the following code to your themes functions.php file:

add_filter( 'asp_pagepost_results', 'asp_add_category_titles', 1, 1 );

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

    // Get the post categories
    $post_categories = wp_get_post_categories( $pageposts[$k]->id );
    $cats = "";

    // Concatenate category names to the $cats variable
    foreach($post_categories as $c){
        $cat = get_category( $c );
        $cats = " ".$cat->name;

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

  return $pageposts;

That's it!