I created a content type called Vouchers. This content type has a field called: Points.

In the other hand I enabled the http://drupal.org/project/Userpoints module which allows users to get points.

I created 2 Vouchers nodes. One of them has the value 10 for the Points field and the other one 15

After, I created a view to show the content type: Vouchers. Now I need to add a filter to show the vouchers node only if its Points field value is lower than the User points value (the current logged user)

Please, look my capture to make this understandable:

enter image description here

  • Check this out drupal.org/node/1389248. The use case is pretty similar. It uses the flags and rules module to flag content which the user has access to.
    – junedkazi
    Dec 19, 2012 at 21:20

1 Answer 1


You can add the same filter programmatically to your view.

 * Implements hook_views_pre_view().
function YOURMODULE_views_pre_view(&$view, &$display_id, &$args) {
  if ($view->name == 'your_view_machine_name') {
    $info = array(
      'table' => 'field_data_field_points', // name of your “Points” field table.
      'field' => 'field_points_value', // name of value field in that table.
      'value' => array('value' => userpoints_get_current_points()), // dynamic part.
      'operator' => '<',
      'id' => 'field_data_field_points_YOURMODULE', // unique id.
      'group' => 100, // new group.
    $handler = views_get_handler($info['table'], $info['field'], 'filter');

    $handler->init($view, $info);
    $view->display_handler->handlers['filter'][$info['id']] = &$handler;


It will automatically join the table and add condition to query.

  • I added an exposed filter and is not shown. If I disable the module I created with your code then it is shown correctly. How can I make your code allow the exposed filter to be shown. Thanks.
    – chefnelone
    Jan 7, 2013 at 15:20

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.