3

Aside from plain SQL, is there any Drupal api to retrive node(s) by passing a node CCK type and a field value?

For example, I would like to get the node which is an Assignment CCK type, by matching an integer CCK field Assignment Score value >= 65.

In PHP.

3

In both D6 and D7, you can use Views. Explaning all of Views is out of scope for this answer, but you can either add two, "Filters" one on content type, and one on field value. This however will require reconfiguring the View if you want to change the score, or type. If you add the same filters as "Contextual Filters", or "Arguments", depending on your Views version, the values can be pulled from the URL. This will allow completely different listings with a single view.

Two URL examples for using contextual filters:

example.com/results/easy_assignment/50
example.com/results/hard_assignment/75

In D7 you have entities, and could in code do:

$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'node')
->entityCondition('bundle', 'assignment')
->propertyCondition('status', 1)
->fieldCondition('field_assignment_score', 'value', 65, '=');
$result = $query->execute();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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