Knowledge Base

Showing the post type name in result title

in Ajax Search Pro Tips Tags: ajaxfiltermodifypost typesearchtitle

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_show_the_post_type', 1, 1 );

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

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

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

  return $pageposts;
}

Voila!