2

I've got a view where I have to change the value of a field in certain conditions. I managed to change the value of the field before it's printed but It doesn't affect how the elements are sorted.

In my case, I use the field price as sorting and my code is:

function real_estast_sub_preprocess_views_view_fields(&$vars) {

  $view = $vars['view'];

  foreach ($view->field as $id => $field) {   

    // change the field value depend on result (node id)
    if($vars['view']->name == 'properties'){  

        $vars['fields']['field_price_1']->content = "";

        if (isset($_SESSION["pricesfromnodeid"][$vars['row']->nid])){

          $vars['fields']['field_price']->content = "<div class='price-content'><div class='field-content'>".$_SESSION["pricesfromnodeid"][$vars['row']->nid]."€</div>";
          $vars['row']->field_data_field_price_field_price_value = $_SESSION["pricesfromnodeid"][$vars['row']->nid];

        }else{

          $vars['fields']['field_price']->content = "<div class='price-content'><div class='field-content'>".$vars['row']->field_data_field_price_field_price_value."€/night</div>";
        }

      }else{

      }        
  }
}

Is it possible to affect the sorting at this point?

I got the answer for this problem in another question:

How to sort a view using values not stored in the database>values-not-stored-in-the-database

1

Browse other questions tagged or ask your own question.