Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Finetuning search results › Reply To: Finetuning search results
Hi Georg,
Thank you for the details, it helps a lot!
1. Yes – for the vertical results layout there is a grouping feature. I believe the grouping by post type will help with your case.
2. The file content text is not easy to access, that would not work. However the page excerpt (where the media is attached to), could potentially work via a custom code.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
add_filter( 'asp_results', 'asp_attachment_content_field', 10, 1 );
function asp_attachment_content_field( $results ) {
foreach ($results as $k=>&$r) {
if ( $r->content_type == 'attachment' ) {
$parent_id = wp_get_post_parent_id( $r->id );
if ( !is_wp_error($parent_id) && !empty($parent_id) ) {
// Change the link to parent post permalink
$r->content = wd_substr_at_word( get_post_field('post_content', $parent_id), 130 );
}
}
}
return $results;
}
If all goes well, and the media files are attached to a parent post/page, this should fetch the content of those and append to the result.