K
K
Knowledge Base - Ajax Search Pro for WordPress
Buy Ajax Search Pro!
Documentation
Get Support
Search…
Knowledge Base
Safe Coding Guideline
Hooks
Filters
Templating
Constants
Frontend Filters
Taxonomy Filters
Frontend filters API
Tips & Miscellaneous
Tutorials
Post Types
Index Table - Indexing child post contents to parent
Limit results to specific post IDs only
Filter posts (or CPT) which user can’t access
Restricting results by user Groups using the Groups plugin by itthinx
Limiting results to specific posts by parent ID
Limit results to current page children
Excluding posts or CPT by parent ID(s)
Searching posts, pages (or any CPT) by specified keywords only, nothing else
Showing the post type name in result title or content
Searching within given categories/taxonomy terms only
Search only in the same category as the current post or page (single page)
Search only within the current category (or any taxonomy) archive
Taxonomy Terms
WooCommerce
Compatibility
Other
Other
ASP_Query
REST API
Building a custom REST API
Javascript API
Javascript Hooks
Changelog
Powered By
GitBook
Showing the post type name in result title or content
Displaying post type name in the live results title or content field
What is this, and where do I put this custom code?
Post type name in title
1
add_filter
(
'asp_results'
,
'asp_show_the_post_type_title'
,
10
,
1
);
2
function
asp_show_the_post_type_title
(
$results
)
{
3
foreach
(
$results
as
$k
=>&
$r
)
{
4
if
(
isset
(
$r
->
post_type
)
)
{
5
// Modify the post title
6
$post_type_obj
=
get_post_type_object
(
$r
->
post_type
);
7
$r
->
title
=
$post_type_obj
->
labels
->
singular_name
.
' - '
.
$r
->
title
;
8
}
9
}
10
11
return
$results
;
12
}
Copied!
Post type name in content
1
add_filter
(
'asp_results'
,
'asp_show_the_post_type_content'
,
10
,
1
);
2
function
asp_show_the_post_type_content
(
$results
)
{
3
foreach
(
$results
as
$k
=>&
$r
)
{
4
if
(
isset
(
$r
->
post_type
)
)
{
5
// Modify the post title
6
$post_type_obj
=
get_post_type_object
(
$r
->
post_type
);
7
$r
->
content
=
$post_type_obj
->
labels
->
singular_name
.
' - '
.
$r
->
content
;
8
}
9
}
10
11
return
$results
;
12
}
Copied!
Previous
Searching posts, pages (or any CPT) by specified keywords only, nothing else
Next
Searching within given categories/taxonomy terms only
Last modified
11mo ago
Copy link
Contents
Post type name in title
Post type name in content