The code below is from this link. It basically creates a hit counter, but I'm probably gonna have to do this by IP.

How do I make a WP_Query, where only posts up to 1000 views can be seen on the trending list? Of course. I would want to do it by date as well, but it won't appear at the top one after another, it will only be in the list where it was originally posted. So, that's another solution I'm gonna need to figure out.

This is similar to 9GAG.

//Add to functions.php
    function get_hits(){
    global $post;
    $hits = get_post_meta($post->ID, '_hit-counter', true);
    return $hits;

function update_hits($count){
    global $post;
    $count = $count ? $count : 0;
    $hits = update_post_meta($post->ID, '_hit-counter', $count++);
    return $hits;

//Usage within the loop

This should work, but I didn't have the time to test it.

$query = new WP_Query( array( 'meta_key' => '_hit-counter', 'meta_value' => '1000', 'meta_compare' => '>=', 'orderby' => 'date' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.