1 comment

  1. The issue wasn’t with the post data, but with the output of the values themselves. The arrays were connected together causing the first words of all strings to be attached to the previous array values:

      $searched =  get_search_query();
      $custom_fields = get_post_custom();
    
      foreach($custom_fields as $field_key => $field_values) {
        foreach($field_values as $key => $value) {
    
          if (stripos($value, $searched) !== false) {
            $in = $value;
            $search = $searched;
            $replace = '<strong>' . $searched . '</strong>';
            $out = str_ireplace($search, $replace, $in);
            echo '<p>' . $out . '</p>';
          }
        }
      }
    

Comments are closed.