Hi, I'm trying to execute some php code before displaying a view of a node "repas".
In fact, in my view I have two filters : one for the date and the second for the type of meal.
I would like to create a node based on values of filters when I have no result for the search.
The node "repas" (to create) have several fields. Among these fields I have the two filters fields which are required to create the node and only those ones. There is no node who have the same combination of the date and the type of meal. Only one result may appear at a time.
type of meal is a vocabulary which is an entity reference field of the content type "repas".
Date is a Date field of the content type "repas".

To finish this explication, the solving of this problem will always display a result for the search because the node will be created before displaying the view depending on the values of filters.

In this php code, I didn't get values of filters to create the node.
I don't know where I can use this script. I have installed 'views PHP' to include php code in the filter criteria of the view but it doesn't work.

global $user;

$values = array(
'type' => 'repas',
'uid' => $user->uid,
'status' => 1,
'comment' => 0,
'promote' => 0,
);

$entity = entity_create('node', $values);

$ewrapper = entity_metadata_wrapper('node', entity);

$ewrapper->title->set('Mon repas');
$ref_type_de_repas_id = 3;
$ewrapper->field_type_de_repas->set(intval($ref_type_de_repas_id));
$date_repas = new DateTime('February 2, 2014');
$entity->field_repas_date[LANGUAGE_NONE][0]= array(
'value' => date_format($date_repas, 'd-m-Y'),
'timezone' => 'UTC',
'timezone_db' => 'UTC'
);
$ewrapper->save();

source : Create a Node in Code

Thanks,

sokarcreative