Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Adding total views count as a field or filter works fine but it's not available as a sort for some reason like it is on regular content views.
Comments
Comment #1
mcrittenden CreditAttribution: mcrittenden commentedUpdates, doesn't work as a filter either, and it appears that view counts are not stored by mongo at all. So it sounds like mongo first needs to make node view counts available before this can be accomplished. Moving this to postponed until #1125886: Support of the core statistics module or something like it lands.
Comment #2
mcrittenden CreditAttribution: mcrittenden commentedI ended up just hacking my way around this by 1) adding a regular integer field for view count to the content type, 2) incrementing that field via a custom script that avoids a full drupal bootstrap, and 3) adding the new field to the view as a sort.
Script is below. Put it in the site root as inc.php and use it as an image src like
<img src="/inc.php?nid=<nid>" />
whenever you want to increment something. It outputs a 1x1 gif. Thanks to @chx for the bulk of this code.Comment #3
mcrittenden CreditAttribution: mcrittenden commentedComment #4
chx CreditAttribution: chx commentedAlso please share the Views code. I guess it's a hook_views_data_alter() against efq.
Comment #5
mcrittenden CreditAttribution: mcrittenden commentedNo views code. It's just a regular field added to the content type via the fields GUI, so views can display it and sort by it without any custom code. Like I said, it's a hack, but it worked fine in this situation.
Comment #6
chx CreditAttribution: chx commentedOh I missed that! Very tricky. Will commit something to this end.