drupallocationcck

Programmatically update Drupal CCK field


How can I update a cck field programmatically?

I am trying the following code, without any success:

$node->location[field_location][0][city]    =   'tracker city';
    $node->location[field_location][0][latitude]    =   8.888888;
    $node->location[field_location][0][longitude]   =   9.999999;

I am aware I could directly interact with the database but I am looking for a different solution.


Solution

  • You should be able to put this in your presave, and have it save properly. I'm not 100% sure that city, latitude, and longitude are the correct keys, but I'm leaving them since you had them.

    $node->field_location[0][city]      = 'tracker city';
    $node->field_location[0][latitude]  = 8.888888;
    $node->field_location[0][longitude] = 8.999999;
    

    If that does not work, you should install the Devel module and use the Node 'Devel' tab to view the node object and see exactly what the proper format is.