Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › How to show short description for Pages in results › Reply To: How to show short description for Pages in results
March 3, 2021 at 3:49 pm
#31949
Keymaster
Thanks!
I may have found a possible solution. I have added the following custom code to the functions.php file in your theme directory. Please keep it there:
add_filter('asp_results', 'asp_fg_results', 10, 1);
function asp_fg_results($results) {
foreach ( $results as $k => &$r ) {
if ( $r->content == '' ) {
$groups = acf_get_field_groups(array('post_id' => $r->id));
foreach ( $groups as $group ) {
$fields = acf_get_fields($group['key']);
foreach ( $fields as $field ) {
$s = get_field($field['name'], $r->id);
if ( !empty($s) ) {
$r->content = wd_substr_at_word(strip_tags($s), 150) . '..';
break 2;
}
}
}
}
}
return $results;
}
The page contents were indeed empty. Everything was build via ACF, which is unfortunately not searchable and is not returned when requesting the post content. The function above should take care of it to some extent.