# Showing the post type name in result title or content

[What is this, and where do I put this custom code?](/safe-coding-guideline.md)

### Post type name in title

```php
add_filter( 'asp_results', 'asp_show_the_post_type_title', 10, 1 );
function asp_show_the_post_type_title( $results ) {
  foreach ($results as $k=>&$r) {
		if ( isset($r->post_type) ) {
			// Modify the post title
			$post_type_obj = get_post_type_object( $r->post_type );
			$r->title = $post_type_obj->labels->singular_name . ' - ' . $r->title;
		}
  }

  return $results;
}
```

### Post type name in content

```php
add_filter( 'asp_results', 'asp_show_the_post_type_content', 10, 1 );
function asp_show_the_post_type_content( $results ) {
  foreach ($results as $k=>&$r) {
		if ( isset($r->post_type) ) {
			// Modify the post title
			$post_type_obj = get_post_type_object( $r->post_type );
			$r->content = $post_type_obj->labels->singular_name . ' - ' . $r->content;
		}
  }

  return $results;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://knowledgebase.ajaxsearchpro.com/miscellaneous/post-types/showing-the-post-type-name-in-result-title.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
