I am creating a module in Drupal 7, where I need to have a list of all nodes created by a logged in user of specific content type. How can I achieve this? It is easy to do it in view but I need to do it in a custom module. Can anybody help?
Thanks
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.
Sign up to join this communityI am creating a module in Drupal 7, where I need to have a list of all nodes created by a logged in user of specific content type. How can I achieve this? It is easy to do it in view but I need to do it in a custom module. Can anybody help?
Thanks
There is module available https://drupal.org/project/usercontent still if you want to do it in custom module then here is the code:
global $user;
$node_query = db_select('node', 'n')
->fields('n',array('nid'))
->condition("type", "node type")
->condition("uid", $user->uid)
$node_result = $node_query->execute()->fetchAll();