Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
Node is saved as draft in My Content >> Draft
  • Query Alter in Views

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 3
    Comment on it

    In order to modify the where condition of a views query we use hook_views_query_alter. This hook should be placed in your custom module.

     //Here, we are going to modify the query, which is an element of the $query variable
    function hook_views_query_alter(&$view, &$query) {
      // Example assuming a view with an exposed filter on node title.
      // If the input for the title filter is a positive integer, filter against
      if ($view->name == 'my_view' ) {
        foreach ($query->where as &$condition_group) {
          foreach ($condition_group['conditions'] as &$condition) {
            if ($condition['field'] == 'node.title') {
              $condition = array(
                'field' => 'node.nid',
                'value' => $view->exposed_raw_input['title'],              // can change value 
                'operator' => '=',           // can change operature here if required
              );
            }
          }
        }
      }
    }
    
    drupal7

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: