Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Search results content › Reply To: Search results content
March 11, 2025 at 3:49 pm
#53278
Keymaster
All right, the setup seems to be okay, all you need the the excerpt.
Make sure that this custom code is also applied with the previous ones. I can’t check as I can only see the development environment:
add_filter( 'asp_results', 'asp_get_attachment_to_product_content', 10, 4 );
function asp_get_attachment_to_product_content( $results, $search_id, $is_ajax, $args ) {
// --- DO NOT CHANGE ANYTHING BELOW ---
foreach ( $results as $k =>&$r ) {
if ( $r->post_type !== 'product' ) {
continue;
}
$product = wc_get_product( $r->id);
if ( $product->is_downloadable() ) {
// Loop through WC_Product_Download objects
foreach ( $product->get_downloads() as $key_download_id => $download ) {
$download_link = $download->get_file(); // File Url
$id = asp_get_file_id_from_url($download_link);
if ( $id !== '' ) {
$field_value = get_post_meta( $id, '_asp_attachment_text', true );
if ( $field_value !== '' ) {
$r->content = wd_substr_at_word($field_value, 130);
break;
}
}
}
}
}
return $results;
}
This fetches the attachment text and replaces it in the live product results.
-
This reply was modified 1 year, 2 months ago by
Ernest Marcinko.