Why the views doesn't have the ability to filter the nodes only who have new comments -_-

there's only for Node:Has a new content

....

Is there a way to make views filter only nodes with new comments?

Comments

vertazzar’s picture

bump

DarkLight’s picture

BUMP - Desperately need this filter, guys! :/ Any news?

Leksat’s picture

You can use filter "Has new content" with a little modification.

/**
 * Implementation of hook_views_query_alter().
 */
function MODULENAME_views_query_alter(&$view, &$query) {
  
  // Modify filter "Has new content" to "Has new comments".
  if ($view->name == 'VIEWNAME') {
    foreach ($query->where[0]['clauses'] as &$clause) {
      if (strstr($clause, 'last_comment_timestamp')) {
        $clause = 'history_user.timestamp < node_comment_statistics.last_comment_timestamp';
      }
    }
  }
}
mr.j’s picture

Thank you thank you thank you.

Georgii’s picture

BTW for D7 you should switch to

/**
* Implementation of hook_views_query_alter().
*/
function MODULENAME_views_query_alter(&$view, &$query) {
 
  // Modify filter "Has new content" to "Has new comments".
  if ($view->name == 'VIEWNAME') {
    foreach ($query->where[0]['conditions'] as &$clause) {
      if (strstr($clause['field'], 'last_comment_timestamp')) {
        $clause['field'] = 'history.timestamp < node_comment_statistics.last_comment_timestamp';
      }
    }
  }
}
JLeMosy’s picture

I've created a module called "utm_mods" that includes only the following PHP code, and I'm still unable to get Views 3 to include comments in the "Has new content" filter. Not sure what I'm missing here, or even if I'm doing this quite right...

/**
 * Implementation of hook_views_api().
 */
function utm_mods_views_api() { // your module name into hook_views_api
  return array(
    'api' => 3,
    // might not need the line below, but in any case, the last arg is the name of your module
    'path' => drupal_get_path('module', 'utm_mods'),
  );
}

/**
* Implementation of hook_views_query_alter().
*/
function utm_mods_views_query_alter(&$view, &$query) {
  // Modify filter "Has new content" to "Has new comments".
  if ($view->name == 'whats_new') {
    foreach ($query->where[0]['conditions'] as &$clause) {
      if (strstr($clause['field'], 'last_comment_timestamp')) {
        $clause['field'] = 'history.timestamp < node_comment_statistics.last_comment_timestamp';
      }
    }
  }
}

Any help wold be great...Thanks!

antoinetooley’s picture

Hey JLeMosy,
did you manage toget this working in the end? I am after this functionality but I can't seem to get any response from my view. Would really apprecaite any help if you did suceed in the end or if anyone else knows what is wrong here?

One thing though is I don't want to replace new content filter I just want to add a new filter whih searched for nodes with new comments so I can use both simultaneously. Does anyone know if this still possible with this custom module approach?

Thanks

Antoine

monstrfolk’s picture

Very simple way to do this....using module views php filter.

1. Add Content:Nid field to view
2. Add Views PHP filter to view.
3. Enter in the filter

return comment_num_new($data->nid) == 0;

That will return only rows with new comments.