WP Document Revisions
[resolved] Get most viewed documents? (5 posts)

  1. Christoph
    Posted 4 years ago #

    Is there a way to sort by the most viewed documents or display a download counter for each document? If documents are really posts, plugins like wp-postviews could work?


  2. Christoph
    Posted 3 years ago #

    ... just tried wp-postviews, but it doesn't count the document downloads. Anyone any ideas where to start? Thank you!

  3. Ben Balter
    Plugin Author

    Posted 3 years ago #

    If you have any caching, this would be impossible.

    You could hook into the serve_document hook, and create this functionality, but nothing exists out of the box.

    If you do make this work, I would love to add the code to the plugin's code cookbook.

  4. Christoph
    Posted 3 years ago #

    I've sent you the code via e-mail.

  5. Christoph
    Posted 3 years ago #

    Here's the code that makes WP Document Revisions work together with wp-postviews.

    Into functions.php:

    add_action( 'serve_document', 'update_document_views');
    function update_document_views($post_id) {
    $post_views = intval(get_post_meta($post_id, 'views', true));
    if ($post_views) update_post_meta($post_id, 'views', ($post_views+1));
    else add_post_meta($post_id, 'views', 1, true);

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Document Revisions
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.