tags:

views:

12

answers:

1

Nodes with cck checkboxes need counting nodes based on cck data and displaing via views field

In drupal6 + taxonomy - there is a simple and fast function taxonomy_term_count_nodes() But I`m thinking about d7 without taxonomy via cck custom field

Are there any API functions for counting nodes based on CCK fileds ?

A: 

I don't know if there is an API function to count nodes with CCK fields in D7, but there's nothing magical about API functions, you can easily create the function yourself if you need it. I don't know how the table structure is going to be, but if it looks like CCK in D6, you could do something like this:

function mymodule_field_node_count($content_type, $field_name) {
  return db_result(db_query("SELECT COUNT(*) FROM {field_%s}
                             WHERE %s <> NULL AND %s <> '';",
                             $content_type, $field_name, $field_name));
}

You could probably make it prettier than the above, this is just to show that is you need to do something, you can just create a function to solve it for you. After all many API functions is often little more than a bit of logic and some queries that's commonly needed.

googletorp