Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
update_hits(get_hits());
share|improve this question

1 Answer 1

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' ) );
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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