Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By enochRoot on
Hi all,
after a lot of searching I still don't know how I can get all fields for a specific content-type.
Any help would be appreciated.
eR
Comments
Gonna need to be more
Gonna need to be more specific than that.
more specific
I'll try:
Every Content-type can have certain fields, right? The ones I can manage by clicking 'manage fields' right next to the content-type under admin/structure/types.
Now I just want to get that list of available fields for that content-type in code.
probably still not specific enough...
Sounds like you are looking
Sounds like you are looking for field_info_instances()
sounds good
The description indeed looks like that's what I need. Can I use the content-type (node-type) as the $entity_type parameter?
thx,
eR
entity type would be 'node'
entity type would be 'node' and the bundle would be the machine name for the content type.
in Drupal6 this does the
in Drupal6 this does the trick:
http://drupal.org/node/1002634#comment-4575544
For Drupal 7
This is an example for Drupal 7
more elegant approach
well, more elegant using the api:
$fields = field_info
$fields = field_info_instances("node", "my_content_type");
Some of that code is for D7.
Some of that code is for D7. field_info_instances is only on D7.
Here's my D6 code: