I have a node which have entity reference autocomplete widget field. I am referencing node of particular content type. But when I come to select node from entity reference field it shows all node created on particular content type. I don't want all node of a content type only wants those node created by current user. Following code is working for select list and I am able to filter node created by specific user where $cType is the name of content type.

    function nirvana_item_offer($cType) {
      global $user;
      $nirvanaQuery = db_select('node', 'n')
        ->condition('uid', $user->uid, '=')
        ->condition('type', $cType, '=')
        ->condition('status', 1, '=')
        ->fields('n', array('nid', 'title'))
      $result = array();
        $result['_none'] = '- None -';
        foreach ($nirvanaQuery as $node) {
          $result[$node->nid] = $node->title;

      return $result;

Above function is returning only those node created by current user. How can I achieve same for autocomplete widget.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.