This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Problem with filters when redirect to result page.

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Problem with filters when redirect to result page. Reply To: Problem with filters when redirect to result page.

#24846
Ernest MarcinkoErnest Marcinko
Keymaster

Hi!

I honestly don’t know what exactly went wrong there. I suppose it was caching or something?

The product features seems to be stored within the ‘aps-product-features’ custom field. I am not sure about how it is stored, but I am guessing it stores all the features as an array(?).
For that, you will need a custom code to print to the results list.

I have constructed a custom code, that may help you start with it.
Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

add_filter( 'asp_results', 'asp_custom_field_to_results', 10, 1 ); 
function asp_custom_field_to_results( $results ) {
  $custom_field = 'aps-product-features'; // Enter the custom field name
  $field = 'content';               // 'title' or 'content'
  $position = 'after';           // 'before' or 'after'
  $delimiter = ' ';               // character between the field value and the field

  foreach ($results as $k=>&$r) {
    if ($r->content_type != 'pagepost') continue;
    if ( function_exists('get_field') )
        $meta_value = get_field( $r->id, $custom_field, true ); // ACF support
    else
        $meta_value = get_post_meta( $r->id, $custom_field, true );
            
    // Modify the post title to add the meta value
    if ( !empty($meta_value) ) {
      if ( is_array($meta_value) ) {
        $s = '';
        foreach ( $meta_value as $v ) {
          if ( is_array($v) && isset($v['name'], $v['value']) ) {
             $s .= "<p>".$v['name'].": ".$v['value']."</p>";
          }
        }
        $meta_value = $s;
      }
    
      if ( $field == 'title' ) {
        if ( $position == 'before' )
          $r->title  = $meta_value . $delimiter . $r->title;
        else
          $r->title  .= $delimiter . $meta_value;
      } else {
        if ( $position == 'before' )
          $r->content  = $meta_value . $delimiter . $r->content;
        else
          $r->content  .= $delimiter . $meta_value;
      }
    }
  }
 
  return $results;
}