Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3275718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:10:33+00:00 2026-05-17T19:10:33+00:00

I try to programmatically create a node of custom contenttype location in Drupal 6,

  • 0

I try to programmatically create a node of custom contenttype “location” in Drupal 6, with the node containing a location field (http://drupal.org/project/location) called “location” (yes I know, the nomenclature could be better, but I am just experimenting on this at the moment).

Creating the node works just fine, but I cannot find a way to set the contents for the location field – i.e. the node is created with all content but the value for then location field.

I try creating the node like this:

        $newNode = (object) NULL;
        $newNode->type = 'location';
        $newNode->title = $locationName;
        $newNode->uid = $userId;
        $newNode->created = strtotime("now");
        $newNode->changed = strtotime("now");
        $newNode->status = 1;
        $newNode->comment = 0;
        $newNode->promote = 0;
        $newNode->moderate = 0;
        $newNode->sticky = 0;

        $newNode->field_location[0]['street'] = 'Teststraße';
        $newNode->field_location[0]['postal_code'] = '12345'; 
        $newNode->field_location[0]['city'] = 'Musterstadt'; 

        node_save($newNode);

The node gets created with the correct title, but the location fields remain unset.

How can I programmatically set the location-related fields?

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:10:33+00:00Added an answer on May 17, 2026 at 7:10 pm

    Wanted to add this as a comment, but it seems like putting code into the comment is rather problematic. So here we go: I changed the internas so that I do not use a cck field anymore, but use the default location option as suggested by googletorp.

    The actual code to create a new location and assign this to a new node looks like this:

    $location['street'] = "myStreet";
    $location['postal_code'] = "12345";
    ...
    
    $newLocationId = location_save($location);
    
    $newNode = ...
    $newNode->locations[0]['lid'] = $newLocationId;
    
    node_save($newNode);
    

    Thanks for the guidance 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I try to fetch a Wikipedia article with Python's urllib: f = urllib.urlopen(http://en.wikipedia.org/w/index.php?title=Albert_Einstein&printable=yes) s
Did anyone try to read programmatically an Alibre Design CAD file? I see that
I programmatically create a Picture Box in c# windows program. I assign it with
I'm looking for a place to hook some code to programmatically create, size and
How does one create a JAR file programmatically using java.util.jar.JarOutputStream ? The JAR file
When i create a iboutlet to my navigationController and try to add it to
I am trying to create a .vcf file programmatically in C#, and writing a
What I try is to import several tables programmatically from Microsoft SQL Server to
I am wanting to create a contact programmatically into the local addressbook (so that
In order to try the memory leaks instrument tool, I create a view-based ipad

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.