0

I want to retrieve field values of some nodes in Drupal 6. Can I do this without writing a module as it is a small thing. Can I do it using Drush,how to write a drush script for that?

Please anyone help me?

IshaS
  • 837
  • 1
  • 10
  • 31

2 Answers2

1

You can write your function in template.php file as you don't want to create a new module. But it is not recommended. It is better to have a common module for the whole project for this kind of functions.

  • can I do it by Drush script?As a small thing I was advisable for not to write a module.Thanks for the answer. – IshaS Oct 05 '14 at 12:57
1

You can use the "php-eval" drush argument, abbrevated with "eval":

drush @mysite eval '$nid = 12; $node = node_load($nid); var_export($node, TRUE);'

I wrote this script explicit, here is the shortened version:

drush @mysite eval 'var_export(node_load(12), TRUE));'

Running this command you get to know the structure of the node object. If you know the field name, then run it like this:

drush @mysite eval 'var_export(node_load(12)->field_body, TRUE));'

The essence is: Take drush eval and run node_load() to get the node object.

DirkR
  • 344
  • 1
  • 5
  • Can I run it in the drush command prompt without writing a code inside the module? – IshaS Oct 13 '14 at 04:14
  • 1
    Yes, all the above code is run at the shell prompt (and thus in the "drush prompt"). No Drupal code modification is needed. – DirkR Oct 14 '14 at 10:29