• Resolved Travelographer

    (@travelographer)


    Hey!

    At first: Thank your for your awesome theme, guys.

    It works great and looks pretty nice. Unfortunately I found a small bug in the popular post widget.

    Your query delivers the posts ordered by post views and should provide us the most popular posts.

    Unfortunately the post views are stored as strings not as numbers.

    Therefore the sort order looks like

    1. 95
    2. 739
    3. 63
    4. 4001
    5. 30122

    but it should look like

    1. 30122
    2. 4001
    3. 739
    … and so on

    Do you have any ideas how to fix it? Is there a possibility to cast the values?

    Best regards
    Christian

Viewing 1 replies (of 1 total)
  • Hi Christian,

    I hope you are well today and thanks for posting here.

    I could confirm the issue on my test site therefore i have notified the theme developer about it so that it can be fixed.

    In the meanwhile you can resolve the issue by editing the following Dazzling theme files.

    Change the code in the following dazzling theme file on line number 231

    /dazzling/inc/extras.php

    Before Editing :

    function dazzling_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{

    After Editing :

    function dazzling_setPostViews($postID) {
        $count_key = 'post_views_count';
        $count = (int)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{

    Change the code in the following dazzling theme file on line number 45

    /dazzling/inc/popular-posts-widget.php

    Before Editing :

    $recent_posts = new WP_Query(array('showposts' => $number, 'ignore_sticky_posts' => 1, 'post_status' => 'publish', 'order'=> 'DESC', 'showposts' => $number, 'meta_key' => 'post_views_count', 'orderby' => 'meta_value'));

    After Editing :

    $recent_posts = new WP_Query(array('showposts' => $number, 'ignore_sticky_posts' => 1, 'post_status' => 'publish', 'order'=> 'DESC', 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num'));

    Please note you are making changes in the theme files therefore you have to make these changes again after theme updation as changes made in the theme files get lost on theme updation.

    Best Regards,
    Movin

Viewing 1 replies (of 1 total)
  • The topic ‘bug in popular post widget’ is closed to new replies.