Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

I created a content type and it has many nodes. And I wrote a custom module to show nodes on the front page.

My nodes order:

 $themeurl = '/drupal/'.path_to_theme().'/images';
    $sql = "SELECT * FROM `node`
            LEFT JOIN `field_data_field_anasayfa_catwalk` ON `field_data_field_anasayfa_catwalk`.`entity_id` = `node`.`nid`
            WHERE type = 'designers_albums'
            AND `node`.`status` = 1
            AND `node`.`language` = '".$language->language."'
            AND `field_data_field_anasayfa_catwalk`.`field_anasayfa_catwalk_value` = 1
            ORDER BY `node`.`created` ASC";

But now, I installed the Weight module and want to sort by weight. How can I change this option?
Thank you.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

You'll just have to add another JOIN to the weight_weights table on your query.

The weight_weights table stores the entity_id, entity_type and the weight value.

EDITED

Here goes an example:

$sql = "SELECT * FROM `node`
        LEFT JOIN `field_data_field_anasayfa_catwalk` ON `field_data_field_anasayfa_catwalk`.`entity_id` = `node`.`nid`
        LEFT JOIN `weight_weights` ON `weight_weights`.`entity_id` = `node`.`nid`
        WHERE type = 'designers_albums'
        AND `node`.`status` = 1
        AND `node`.`language` = '".$language->language."'
        AND `field_data_field_anasayfa_catwalk`.`field_anasayfa_catwalk_value` = 1
        ORDER BY `weight_weights`.`weight` ASC";
share|improve this answer
    
Thank you! Can you give me sample? –  Karmacoma Jan 17 '13 at 15:53

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.