Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Show document related posts › Reply To: Show document related posts
October 20, 2022 at 9:01 am
#39726
Keymaster
Yes, I think so – it has to be added via the code, as those elements are added programmatically, and some of the options will not apply to them. Please change the custom code to this:
add_filter('asp_results', 'asp_return_posts_by_attachment_results');
function asp_return_posts_by_attachment_results($results) {
$ids = array();
$parent_ids = array();
$new_results = array();
// Gather existing post results first
foreach($results as $k=>&$r){
if ( isset($r->post_type) ) {
if ( $r->post_type == 'attachment' ) {
$parent_ids[] = wp_get_post_parent_id($r->id);
unset($results[$k]);
} else {
$ids[] = $r->id;
}
}
}
$parent_ids = array_unique(array_diff($parent_ids, $ids, array(0)));
foreach ( $parent_ids as $id ) {
$res = new stdClass();
$res->id = $id;
$res->title = get_the_title($id);
$res->content = get_the_content(null, false, $id);
$res->image = get_the_post_thumbnail_url($id);
$res->content = wd_substr_at_word(strip_tags($res->content), 130);
$res->post_type = get_post_type($id);
$res->link = get_permalink( $id );
$res->content_type = 'pagepost';
$res->date = @date_i18n(get_option('date_format', "Y-m-d") . " " . get_option('time_format', "H:i:s"), get_post_time('U', false, $id));
$res->author = get_the_author_meta( 'display_name' , get_post_field ('post_author', $id));
$new_results[] = $res;
}
return array_merge($new_results, $results);
}