• Resolved jeponkz

    (@jeponkz)


    Hi,

    I have manually added a code to sort the posts by popularity.

    Here is the code for the sort by popularity.

    if ($_POST[‘sortby’] == ‘bypop’) {

    $query_args = array(
    ‘category_name’ => $current_category,
    ‘showposts’ => 12,
    ‘meta_key’ => ‘views’,
    ‘orderby’ => ‘meta_value_num’,
    ‘order’ => ‘DESC’,
    ‘paged’ => $paged );
    }

    $wp_query = new WP_Query();
    $wp_query->query($query_args);

    The problem is that, it doesn’t show posts with 0 views. It will only display posts that has views. How can I display all of the posts including posts with 0 views? Thanks.

    https://www.ads-software.com/plugins/wp-postviews/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Lester Chan

    (@gamerz)

    Could you check of those posts with 0 views has already a custom field called “views” with the value 0 to it?

    If those posts has been created before WP-PostViews was installed, you probably have to create a custom field called views with a value 0.

    Thread Starter jeponkz

    (@jeponkz)

    Hi Lester ,

    Thank you for your reply. Unfortunately those posts doesn’t have a custom field called “views”.

    The problem is that, there were about 3k posts without a custom field called “views”, is there a way where I can add a custom field and add a value for all of the posts? Thanks.

    Plugin Author Lester Chan

    (@gamerz)

    Not that I am aware of, you will probably have to write a script for it to check if the post has a views meta field if not you have to add that in.

    Or find a plugin that can do it like https://www.ads-software.com/plugins/mass-custom-fields-manager/. Google is your best friend =)

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not display posts with 0 views’ is closed to new replies.