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?


  • 1
    Hello and welcome. Why not to simply use the same query views generates? What's your actual problem? I don't think we can provide full step by step module creation how to, so please tell us where you encountered a problem. – Mołot Jul 19 '13 at 7:13
  • This inmotionhosting.com/support/edu/drupal-7/views-module-tutorial/… will help you to enable and display queries with view output.. – mohit_rocks Jul 19 '13 at 7:22

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')
->condition("type", "node type")
->condition("uid", $user->uid)
$node_result = $node_query->execute()->fetchAll();

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.