开发者

how to alter drupal-6 view-2 query

开发者 https://www.devze.com 2023-04-05 18:05 出处:网络
I\'m trying to update view query using drupal hook_views_pre_execute(). It\'s updating the query properly but even my query returning only couple of record, in view page it\'s showing pagination at th

I'm trying to update view query using drupal hook_views_pre_execute().

It's updating the query properly but even my query returning only couple of record, in view page it's showing pagination at the bottom开发者_如何转开发 but i've set the page limit 10. Can any one advise me how to resolve this issue.

function mymodule_views_pre_execute(&$view)
{ 
  switch($view->name)
  {
      case 'test_merchandise':
            $view->build_info['query'] = "MY QUERY";
            drupal_set_message($view->build_info['query']);
      break;
  }
}


if you want to alter views query then use this method

function modulename_views_query_alter(&$view, &$query){

    if ( $view->name == 'test_merchandise' ) {
        //here you will get the whole $query object and alter only the place you want change
        $query->orderby[0] = "substring(node_data_field_date_field_date_value,1,4) DESC";
        echo "<pre>";print_r($query);echo "</pre>";
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消