Viewing 1 replies (of 1 total)
  • Thread Starter Peter023

    (@peter020)

    Anyone?

    Maybe I need to clarify a bit, i’m sure it is possible:

    I use a widget with the most popular tracks. The list is sorted by most views.

    The views are counted by adding this snippet to function.php:

    function getPostViews($postID){
    $count_key = ‘post_views_count’;
    $count = get_post_meta($postID, $count_key, true);
    if($count==”){
    delete_post_meta($postID, $count_key);
    add_post_meta($postID, $count_key, ‘0’);
    return “0 View”;
    }
    return $count.’ Views’;
    }
    function setPostViews($postID) {
    $count_key = ‘post_views_count’;
    $count = get_post_meta($postID, $count_key, true);
    if($count==”){
    $count = 0;
    delete_post_meta($postID, $count_key);
    add_post_meta($postID, $count_key, ‘0’);
    }else{
    $count++;
    update_post_meta($postID, $count_key, $count);
    }
    }

    // Remove issues with prefetching adding extra views
    remove_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0);

    In the widget my_widget_popular.php I added:

    <?php $args = array(‘showposts’ => $number, ‘nopaging’ => 0, ‘orderby’=>’meta_value_num’, ‘meta_key’ => ‘post_views_count’, ‘order’ => ‘DESC’, ‘post_type’ => array(‘download’), ‘post_status’ => ‘publish’); $mypost = new WP_Query($args); if ($mypost->have_posts()) : ?>

    Now I get a nice list with the most popular tracks based on views.
    This will show all tracks from all categories.
    But I want the list sorted by category. i.e. if I click on category D, the tracks with the most views in that specific category are showing.

    I tried this: https://stackoverflow.com/questions/18555779/how-to-display-popular-post-by-view-in-current-category

    But I think EDD use other queries.

    Thanks!

Viewing 1 replies (of 1 total)
  • The topic ‘Most popular per category’ is closed to new replies.