1
votes

Ok, so I want to write a custom PHP script that I am going to insert into a Drupal content type.

I want this PHP script to be able to pull in the information from other fields in the content type.

Basically, those fields will contain data that the PHP script will use to make a database call, and ultimately display to the end user.

Is it possible to reference a field from the current content type in PHP, inside the content type? (Obviously having the PHP code module enabled is required).

Note this is in Drupal 7

1

1 Answers

0
votes

I thoroughly recommend not using the PHP filter module (it introduces security holes and makes it impossible to version control your code). That said, you can get the node object (and thus it's fields) in code like this:

if ($node = menu_get_object()) {
  $some_field_items = field_get_items('node', $node, 'field_some_field');
  // etc...
}

Bear in mind that method will only work when you're on the full node page.