Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I am programatically saving nodes. From my reading, it sounds as if Path auto is trigged to autmatically create a URL alias when node_save() is called. However, this is not happening.

I later read that I needed to set $node->path_set_alias = TRUE. However, this is not working correctly either.

Using 7.12 and the latest versions of pathauto.

Here is my code.

$node = new stdClass();
        //set other defaults
        node_object_prepare($node);

        $node->type = $page_data['content_type'];
        $node->body[LANGUAGE_NONE][0]['value'] = $page_data['description'];
        $node->body[LANGUAGE_NONE][0]['summary'] = text_summary($page_data['description']);
        $node->body[LANGUAGE_NONE][0]['format']  = 'filtered_html';
        $node->title = $page_data['title'];
        $node->field_product_price[LANGUAGE_NONE][0]['value'] = $page_data['price'];
        $node->field_item_location[LANGUAGE_NONE][0]['postal_code'] = $page_data['zipcode'];
        $node->uid = "1";
        $node->status = 1;
        $node->active = 1;
        $node->pathauto_perform_alias = TRUE;

    //the name of my actual field is 'product images'
    $node->field_product_images[LANGUAGE_NONE] = $images;
    unset($images);




    $node->field_baby_clothes_category[LANGUAGE_NONE][0]['tid'] = $page_data['category']; 

    if($node = node_submit($node)) { // Prepare node for saving
        node_save($node);
}

Thoughts on how to get this to work correctly? Thanks!

share|improve this question
UPDATE - my problem still exists, however, something weird is happening. The paths are being generated and listing correctly in the url alias list. The problem now is Drupal refuses to use them. What I mean is, even though the aliases exist, drupal uses node/xx instead. How do I get Drupal to use the alias? – blue928 Mar 1 '12 at 10:22

1 Answer

up vote 2 down vote accepted

We discussed on Drupal.org that not setting the $node->language property causes this issue to happen. Either setting $node->language = LANGUAGE_NONE or $node->language = 'en' should fix this.

Also using $node->path['pathauto'] = TRUE rather than $node->pathauto_perform_alias for Drupal 7.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.