Find item position in the pager
EDIT (2015-04-05): Updated the snippet to work with newer version of Views.

Us too had to find the page number of a views result on which a certain node appears, so we can redirect visitors to this page.

By loading a view for a specific display and executing it's query manually, we retrieve an array with all node ids which we can search for a specific node id. When we have got the position of the node id, we divide it by the amount of items per page to get the page number the node is on.

I understand that loading all node ids at once in an array probably should not be done on large amounts of records, but for this exercise it's okay.



/**
 * Custom function to get the page number of a views result a node appears on.
 * Based on Drupal's views_get_view_result().
 */
function yourmodulename_views_get_item_page_nr($nid, $name, $display_id = NULL) {
  $args = func_get_args();
  array_shift($args); // remove $nid
  array_shift($args); // remove $name

  if (count($args)) {
    array_shift($args); // remove $display_id
  }

  $view = views_get_view($name);
  if (is_object($view)) {
    if (is_array($args)) {
      $view-&gt;set_arguments($args);
    }

    if (is_string($display_id)) {
      $view-&gt;set_display($display_id);
    }
    else {
      $view-&gt;init_display();
    }

    // Set the limit to 0 to retrieve all node ID's.
    $view-&gt;set_items_per_page(0);

    $view-&gt;pre_execute();
    $view-&gt;build();

    // Get the views query.
    $query = $view-&gt;build_info['query'];

    // Get the return assoc array with return objects, keyed by nids.
    $nids = $query-&gt;execute()-&gt;fetchAllAssoc('nid');

    // Get position of nid in nids array.
    $index = array_search($nid, array_keys($nids));

    // Get amount of items per page.
    $items_per_page = $view-&gt;display[$view-&gt;current_display]-&gt;handler-&gt;get_option('items_per_page'); // As seen at http://api.drupal.org/api/views/includes%21view.inc/function/view%3A%3Aexecute/7.

    // Calculate page number.
    $page_nr = $index === null ? 0 : intval($index / $items_per_page);

    return $page_nr;
  }
  else {
    return 0;
  }
}