1

I've added a custom field to my view using hook_views_data:

/**
 * Implements hook_views_data().
 */
function homepage_views_data() {
  $data['homepage']['table']['group'] = t('Recency field');
  $data['homepage']['table']['join'] = array(
    // Exist in all views.
    '#global' => array(),
  );

  $data['homepage']['recency_field'] = array(
    'title' => t('Recency'),
    'help' => t('Display a calculated recency date'),
    'field' => array(
      'handler' => 'views_handler_recency_field',
      'click sortable' => TRUE,
    ),
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    ),
  );

  return $data;
}

Right now, my field is simply returning the value of node_created. In my field handler:

/**
   * Render callback handler.
   *
   * Return the markup that will appear in the rendered field.
   */
  function render($values) {
    $output = $values->node_created; 
    return $output;
  }

I can add my custom field to a View no problem. But after adding it as a sort field, I get:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'recency_field' in 'field list'

The query looks like this:

SELECT node.title AS node_title, node.nid AS nid, node.created AS node_created, recency_field AS recency_field
FROM 
{node} node
WHERE (( (node.status = '1') ))
ORDER BY recency_field ASC

Does views_handler_sort_date need to work with a real database value?

1
  • recency_field should be in your homepage table as well. Commented Dec 16, 2014 at 8:24

1 Answer 1

0

I believe views lets the database do the sorting, so unless your field exists inside the database, the database controller won't recognise it which is what your error message basically says.

Your Answer

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

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