Reply To: Show image for taxonomy pages in Ajax Search Pro

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Show image for taxonomy pages in Ajax Search Pro Reply To: Show image for taxonomy pages in Ajax Search Pro

#4154
Ernest Marcinko
Ernest Marcinko
Keymaster

Thank you 😉

After some debugging I was able to find the storage method of the images. I’ve implemented the following code to your themes functions.php file:


add_filter( "asp_results", "asp_extra_terms_image_results", 1, 1 );
     
function asp_extra_terms_image_results( $results ) {
   
  foreach ($results as $k=>$v) {
    // get the term images
    if ($results[$k]->image != null && $results[$k]->image != "")
       continue;
     
    /* Try to get woocommerce image */   
    $x = get_woocommerce_term_meta( (int)$v->id, 'thumbnail_id', true );
    if ($x != "")  {
      $im = wp_get_attachment_url( $x );
      if ($im != '') {
        $bfi_params = array('width' => 70, 'height' => 70, 'crop' => true);
        $results[$k]->image = bfi_thumb($im, $bfi_params);
      }
    }
    
    /* Other term image then.. */
    $x = get_metadata("woocommerce_term", (int)$v->id);
    if (isset($x['pa_merk_thumbnail_id_photo'][0])) {
      $im = wp_get_attachment_url( $x['pa_merk_thumbnail_id_photo'][0] );
      if ($im != '') {
        $bfi_params = array('width' => 70, 'height' => 70, 'crop' => true);
        $results[$k]->image = bfi_thumb($im, $bfi_params);
      }
    }
                
  }
     
  return $results;
}

Since it is placed into the themes functions.php file, this code will remain in case of updating the search plugin.

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)