[Drupal] How to add a node to a queue programatically in Drupal?

| | 1 min read

Drupal 7 has a contributed module "Nodequeue" which allows users to collect nodes in an arbitrarily ordered list. It provides a simple drag-and-drop interface to manually order any queue. If you want to create a node to the nodequeue programmatically then you need to read this article. For creating you need to have two things: node id $nid and the queue name queue_name. Here how it can done, we firstly load the nodequeue by name and then add the node to the queue using function nodequeue_subqueue_add. Below code snippets adds a node to the queue.

    $queue = nodequeue_load_queue_by_name(‘queue_name’);
    $subqueue = nodequeue_load_subqueues_by_queue($queue->qid);
    nodequeue_subqueue_add($queue, $subqueue, $nid);

Note : nodequeue_load_subqueues_by_queue returns an array of all subqueues at the queue

Hope it helps you